FieldInfo from Inherited Object

  • Thread starter Thread starter Jack Madeja
  • Start date Start date
J

Jack Madeja

I have a problem with getting FieldInfo from Inherited Object.
Let say I want to do something like this:

Dim l_BF As BindingFlags
l_BF = BindingFlags.OptionalParamBinding Or _
BindingFlags.FlattenHierarchy Or _
BindingFlags.Instance Or _
BindingFlags.NonPublic Or _
BindingFlags.Public Or _
BindingFlags.IgnoreCase
l_Type = obj.GetType
Dim l_Fields As FieldInfo() = l_Type.GetFields(l_BF)
Dim l_Field As FieldInfo
For Each l_Field In l_Fields
l_stkOut.Push(l_Field.Name)
Next
Return l_stkOut

My object is of class B, something like this:

Public Class A
Private _strName As String
Property Name() As String
Get
Return _strName
End Get
Set(ByVal Value As String)
_strName = Value
End Set
End Property
End Class

Public Class B
Inherits A
Private _strAddress As String
Property Address() As String
Get
Return _strAddress
End Get
Set(ByVal Value As String)
_strAddress = Value
End Set
End Property
End Class

In that case I only get Address-property in my returning stack. How
can I get fields from the inherited class A?
 
Jack,

IIRC Reflection never returns inherited private fields. So you have to
walk the inheritance hierarchy (with Type.BaseType) and call GetFields
on each base type.



Mattias
 
Mattias Sjögren said:
Jack,

IIRC Reflection never returns inherited private fields. So you have to
walk the inheritance hierarchy (with Type.BaseType) and call GetFields
on each base type.



Mattias

Thanks Mattias
That really helped! :)
 
Back
Top