List of objects and object values

I have a third-party object that is being passed to one of my methods. An object contains 20 or so line members. How can I easily list all line names and their meanings?

+4
source share
2 answers

Are you talking about properties? If so, you can use reflection:

Dim properties = theObject.GetType().GetProperties() For Each prop In properties Console.WriteLine("{0}: {1}", prop.Name, _ prop.GetValue(theObject, New Object() { })) Next 

This returns all the public properties of the object through GetProperties .

+3
source

Use o.GetType().GetProperties() Then use the PropertyInfo.PropertyType property to make sure it is a string. Then, for the foreach property, call GetValue (o, null)

 props = o.GetType().GetProperties() PropertyInfo prop = props(0) Console.WriteLine (prop.Name & " = " & prop.GetValue (o, Nothing)) 
+1
source

All Articles