How to enumerate all properties of the object and output them?

Discussion in 'ASP .Net' started by GS, Jan 9, 2006.

  1. GS

    GS Guest

    Hi,

    What would be c# code to enumarate all properties of object and output them in a form "property name:value"?

    Thanks,
    GS
     
    GS, Jan 9, 2006
    #1
    1. Advertisements

  2. GS

    Karl Seguin Guest

    Dim txt As New TextBox
    Dim type As Type = txt.GetType()
    Dim properties() As PropertyInfo = type.GetProperties()
    For Each p As PropertyInfo In properties
    Response.Write(p.Name & ":" & CStr(p.GetValue(txt, Nothing)))
    Response.Write("<br>")
    Next

    You should read up the documentation on GetProperties, as it accepts a flag-based enumeration that can change the behaviour.

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    Hi,

    What would be c# code to enumarate all properties of object and output them in a form "property name:value"?

    Thanks,
    GS
     
    Karl Seguin, Jan 9, 2006
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.