473,382 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

FieldInfo from Inherited Object

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?
Nov 20 '05 #1
2 1052
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 [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #2
Mattias Sjögren <ma********************@mvps.org> wrote in message news:<ef**************@TK2MSFTNGP11.phx.gbl>...
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! :)
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: dotnetguy | last post by:
Hello, having a FieldInfo object I'd like to get a reference to the corresponding field object. I know the type of the field object (so I can do a cast if it is required) but I don't know if...
2
by: CA | last post by:
I am learning about attributes and at this point, I am completely confused. I have posted some code below. I do not understand the following points: 1) The TestAttribute does not appear for...
2
by: dotnetguy | last post by:
Hello, having a FieldInfo object I'd like to get a reference to the corresponding field object. I know the type of the field object (so I can do a cast if it is required) but I don't know if...
1
by: David Gouge | last post by:
Posting on behalf of a colleague (no, really! ;) )... Hi, I was wondering if there is any equivalent of FieldInfo.SetValue(Object, Object) that is strongly typed or uses generics? I have been...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.