Home All Groups Group Topic Archive Search About

Reflection - GetValue in a Structure

Author
24 Jul 2006 10:32 AM
John
Hello,

i have this structure..

Public Structure MyStructure
    a as boolean
    b as boolean
    c as boolean
    ....
end structure

Dim Infos() As FieldInfo
Dim fi As FieldInfo
mInfos = GetType(MyStructure).GetFields

for each fi in Infos
    msgbox fi.name
next

I Would "VALUE" for this Field..

Author
24 Jul 2006 12:09 PM
Branco Medeiros
John wrote:
Show quoteHide quote
> Hello,
>
> i have this structure..
>
> Public Structure MyStructure
>     a as boolean
>     b as boolean
>     c as boolean
>     ....
> end structure
>
> Dim Infos() As FieldInfo
> Dim fi As FieldInfo
> mInfos = GetType(MyStructure).GetFields
>
> for each fi in Infos
>     msgbox fi.name
> next
>
> I Would "VALUE" for this Field..

You must provide an 'instance' of your structure to the FieldInfo
class:

Dim X As MyStructure
'...
> for each fi in Infos

  Dim Value As Object = fi.GetValue(X)
  MsgBox fi.Name & "=" & Value.ToString

> next

Regards,

Branco.