Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List object members and values

Tags:

vb.net

I have a 3rd party object that gets passed to one of my methods. The object contains 20 or so string members. How can I easily list all of the string names and their values?

like image 733
Jimmy D Avatar asked Jun 13 '11 18:06

Jimmy D


People also ask

How do you find all the values of an object?

values() Method: The Object. values() method is used to return an array of the object's own enumerable property values. The array can be looped using a for-loop to get all the values of the object.

How can you get list of all properties in an object?

To get all own properties of an object in JavaScript, you can use the Object. getOwnPropertyNames() method. This method returns an array containing all the names of the enumerable and non-enumerable own properties found directly on the object passed in as an argument.

How do you access object members?

Use the member-access operator ( . ) between the object variable name and the member name. If the member is Shared, you do not need a variable to access it.

How do I see all the attributes of an object in Python?

To list all the attributes of an object, use the built-in dir() function. It returns a long list of attribute names, that is, method and variable names of the object. There is a bunch of automatically generated attributes in any Python class.


1 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 public properties of the object via GetProperties.

like image 186
Konrad Rudolph Avatar answered Nov 16 '22 02:11

Konrad Rudolph