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

G

GS

Hi,

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

Thanks,
GS
 
K

Karl Seguin

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top