get menber name,type of a structure

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
 
F

Fergus Cooney

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
 
F

Fergus Cooney

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
 
C

Cc

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)
 
F

Fergus Cooney

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top