I have a class.
Public Class Foo Private _Name As String Public Property Name() As String Get Return _Name End Get Set(ByVal value As String) _Name = value End Set End Property Private _Age As String Public Property Age() As String Get Return _Age End Get Set(ByVal value As String) _Age = value End Set End Property Private _ContactNumber As String Public Property ContactNumber() As String Get Return _ContactNumber End Get Set(ByVal value As String) _ContactNumber = value End Set End Property End Class
I want to loop through the properties of the above class. eg;
Public Sub DisplayAll(ByVal Someobject As Foo) For Each _Property As something In Someobject.Properties Console.WriteLine(_Property.Name & '=' & _Property.value) Next End Sub
Use Reflection:
for Excel – what tools/reference item must be added to gain access to BindingFlags, as there is no ‘System.Reflection’ entry in the list
Edit: You can also specify a BindingFlags value to
type.GetProperties():That will restrict the returned properties to public instance properties (excluding static properties, protected properties, etc).
You don’t need to specify
BindingFlags.GetProperty, you use that when callingtype.InvokeMember()to get the value of a property.