Reflection - GetValue in a Structure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    #1

    Reflection - GetValue in a Structure

    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(MyStruc ture).GetFields

    for each fi in Infos
    msgbox fi.name
    next

    I Would "VALUE" for this Field..


  • Branco Medeiros

    #2
    Re: Reflection - GetValue in a Structure


    John wrote:
    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(MyStruc ture).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.

    Comment

    Working...