Hi All, Using Reflection I am trying to get properties of a class I have created. I am doing this, so I do not have to make coding changes with any additional property added to the class. Getting the properties list is working but I am having trouble reading the value of the property. Not sure how and what parameters to be passed for GetValue funtion. Could anybody please help me with GetValue statement? Thanks in Advance!
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Members As Collection = Family.Members()
For i As Integer = 1 To sqlColl.Count
GetMemberInfo()
Next
End Sub
Sub GetMemberInfo()
Dim oMember As New Member
Dim objType As Type = oMember.GetType()
Dim sName As String, svalue As Object
'Dim properties As System.Reflection.PropertyInfo() = objType.GetProperties()
For Each srcProperty As System.Reflection.PropertyInfo In objType.GetProperties()
sName = srcProperty.Name
svalue = srcProperty.GetValue(oMember , Nothing)
Response.Write(i & " - " & sName & (svalue Is Nothing) & "<br />")
Next
End Sub
'Classes are like
Public Class Member
Private _name As String
Private _age As Integer
Public Property Name() As String
Get
Return \_Name
End Get
Set(ByVal value As String)
\_Name = value
End Set
End Property
Public Property Age() As Integer
Get
Return \_age
End Get
Set(ByVal value As Integer
\_age = value
End Set
End Property
End Class
Public Class Family
Private Shared MemberCollection As Collection = Nothing
Shared Sub AddMember(ByVal Info As Member)
Dim thisFamily As New Family
thisFamily.AddToCollection(Info)
End Sub
Private Sub AddToCollection(ByVal Info As Member)
If MemberCollection Is Nothing Then MemberCollection = New Collection
MemberCollection .Add(Info)
End Sub
Shared Function Members() As Collection
Dim thisFamily As New Family
Return thisFamily.getMembersColl()
End Function
Private Function getMembersColl() As Collection
Return MemberCollection
End Function
Shared Function getCount() As Integer
Return Members.Count
End Class