mardi 7 juin 2016

Accessing Member values

Quick question, hopefully an easy one. I want to get the value stored in a member through this function I have created. I can access the name but not the value, and I cannot figure out a way to use GetValue() on this variable. Any help or Suggestions? Code:

Private Function ObjectsAreSameClass(object1 As IList(Of Object), object2 As IList(Of Object)) As Boolean

    Dim ObjectType As Type = object1.First.GetType()
    Dim AreSameClass As Boolean = Nothing
    Console.WriteLine(ObjectType.ToString)

    If (object1.First.GetType() = object2.First.GetType()) Then
        AreSameClass = True
        Console.WriteLine("Object1 is of type: " + object1.First.GetType().Name)
        Console.WriteLine("Object2 is of type: " + object2.First.GetType().Name)
        If (object1.First.GetType().Name = "Human") Then
            Console.WriteLine("Yep this works")
        End If


    Else
        AreSameClass = False
        Console.WriteLine("Object1 is of type: " + object1.First.GetType().Name)
        Console.WriteLine("Object2 is of type: " + object2.First.GetType().Name)
        If (object1.First.GetType().Name = "Human") Then
            Console.WriteLine("Yep this works")
            Console.WriteLine(object1.First.GetType().GetFields().ToString)
        End If

    End If

    Console.WriteLine()
    Dim MemberArray As MemberInfo() = ObjectType.GetMembers()  'Just Holds members
    For Each Mem In MemberArray
        Console.WriteLine("{0}", Mem.Name)
        Console.WriteLine()
    Next

    Console.WriteLine("Objects are equal? t/f : " + AreSameClass.ToString)

    Return AreSameClass
End Function





Aucun commentaire:

Enregistrer un commentaire