get menber name,type of a structure

  • Thread starter Thread starter Cc
  • Start date Start date
C

Cc

hi ,
how do I get menber of a structure on runtime?
for eample
Structure Person

<VBFixedString(10)> Public ID As String

<VBFixedString(15)> Public Name As String

End Structure



private sub calling()

dim pp as person

test(pp)

end sub



public function test(byref arg_struct as system.valuetype)

' in here I would like to get the menber and value

end function

'---------------------------------------------------------------------------
--

Note

Please don't suggest that I just declare as person on test function
parameter



rgds

cc
 
Hi Cc,

I think what you should be doing is passing in your arg_struct declared as Person rather than ValueType. That way you will have
access to all the members.

Regards,
Fergus
 
Hi again Cc,

Alternatively, lol, you can do this:

public function test(byref arg_struct as system.valuetype)
If TypeOf arg_struct Is Person Then
Dim S As String = DirectCast (arg_struct, Person).ID
End If
end function

:-D

Regards,
Fergus
 
I found a way by doing this
Public Function test(ByVal arg_struct As ValueType)

Dim mi() As MemberInfo

Dim srmMemberInfo As MemberInfo

Dim myfieldinfo As FieldInfo

Dim typTmp As Type

typTmp = arg_struct.GetType()

mi = typTmp.GetMembers()

For Each srmMemberInfo In mi

MsgBox(srmMemberInfo.Name)

Next

end function


but I still don't know how to get the menber data type and size (if fixed
string is used)
 
Hi Cc,

If the TypeOf .. DirectCast solution of no use to you?

Using Reflection is a lot of work. What exactly are you wanting to do?

Regards,
Fergus
 
Back
Top