Vb.net – How to iterate through each property of a custom vb.net object


How can I go through each of the properties in my custom object? It is not a collection object, but is there something like this for non-collection objects?

For Each entry as String in myObject
    ' Do stuff here...

There are string, integer and boolean properties in my object.

Best Solution

By using reflection you can do that. In C# it looks like that;

PropertyInfo[] propertyInfo = myobject.GetType().GetProperties();

Added a VB.Net translation:

Dim info() As PropertyInfo = myobject.GetType().GetProperties()