Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Reflection - GetValue question

Reflection - GetValue question

Scheduled Pinned Locked Moved ASP.NET
questionhelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    peacefulmember
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups