inspecting an object's properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?cm9kY2hhcg==?=

    inspecting an object's properties

    hey all,
    you know how in the immediate window you can inspect an objects property, i
    was just wondering if there was a way to display all that on my web page in a
    div or something?

    thanks,
    rodchar
  • Alberto Poblacion

    #2
    Re: inspecting an object's properties

    "rodchar" <rodchar@discus sions.microsoft .comwrote in message
    news:B6C4192B-12F6-4886-82D8-A1073248C2B4@mi crosoft.com...
    you know how in the immediate window you can inspect an objects property,
    i
    was just wondering if there was a way to display all that on my web page
    in a
    div or something?
    Not automatically, but you can program it by means of Reflection. For
    instance, if you add to your web page a table with ID="tbl", you can display
    the properties of an object with code that is similar to this:

    using System.Reflecti on;
    ....
    Type t = theObject.GetTy pe();
    PropertyInfo pia[] = t.GetProperties ();
    foreach (PropertyInfo pi in pia)
    {
    HtmlTableRow tr = new HtmlTableRow();
    tbl.Rows.Add(tr );

    HtmlTableCell td1 = new HtmlTableCell() ;
    tr.Cells.Add(td 1);
    LiteralControl lc1 = new LiteralControl( pi.Name);
    td1.Controls.Ad d(lc1);

    object propertyValue = pi.GetValue(the Object, null);
    HtmlTableCell td2 = new HtmlTableCell() ;
    tr.Cells.Add(td 2);
    LiteralControl lc2 = new LiteralControl( propertyValue.T oString());
    td2.Controls.Ad d(lc2);
    }

    This displays each of the properties converted to a string. If you wish to
    recursively display the properties of each property, you will have to write
    something more sophisticated, possibly using a tree control instead of a
    table.

    Comment

    • =?Utf-8?B?cm9kY2hhcg==?=

      #3
      Re: inspecting an object's properties

      thanks for the help,
      rod.

      "Alberto Poblacion" wrote:
      "rodchar" <rodchar@discus sions.microsoft .comwrote in message
      news:B6C4192B-12F6-4886-82D8-A1073248C2B4@mi crosoft.com...
      you know how in the immediate window you can inspect an objects property,
      i
      was just wondering if there was a way to display all that on my web page
      in a
      div or something?
      >
      Not automatically, but you can program it by means of Reflection. For
      instance, if you add to your web page a table with ID="tbl", you can display
      the properties of an object with code that is similar to this:
      >
      using System.Reflecti on;
      ....
      Type t = theObject.GetTy pe();
      PropertyInfo pia[] = t.GetProperties ();
      foreach (PropertyInfo pi in pia)
      {
      HtmlTableRow tr = new HtmlTableRow();
      tbl.Rows.Add(tr );
      >
      HtmlTableCell td1 = new HtmlTableCell() ;
      tr.Cells.Add(td 1);
      LiteralControl lc1 = new LiteralControl( pi.Name);
      td1.Controls.Ad d(lc1);
      >
      object propertyValue = pi.GetValue(the Object, null);
      HtmlTableCell td2 = new HtmlTableCell() ;
      tr.Cells.Add(td 2);
      LiteralControl lc2 = new LiteralControl( propertyValue.T oString());
      td2.Controls.Ad d(lc2);
      }
      >
      This displays each of the properties converted to a string. If you wish to
      recursively display the properties of each property, you will have to write
      something more sophisticated, possibly using a tree control instead of a
      table.
      >
      >

      Comment

      Working...