By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

Reflection, GetFields, BindingFlags.

P: n/a
Hello you,

Problem is that Type.GetFields does not return InnerList from a class that
inherits from CollectionBase.

I have a class:

Public Class MyCollection
Inherits System.Collections.CollectionBase
...
End Class

I want to get all the fields from this class:

Dim colFieldsInfo() As FieldInfo
Dim objMyCollection As New MyCollection
colFieldsInfo = objMyCollection .GetType.GetFields(BF.NonPublic, BF.Public,
BF.Instance, BF.Static)

My problem is that MyCollection.InnerList is not added to colFieldsInfo. Why
not?

Are the BindingFlags incorrect? Is there another reason?

Thanks,

Me.
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Dim colFieldsInfo() As FieldInfo
Dim objMyCollection As New MyCollection
colFieldsInfo = objMyCollection .GetType.GetFields(BF.NonPublic, BF.Public,
BF.Instance, BF.Static)
I assume you have Or instead of commas in your actual code, or that
wouldn't even compile.

My problem is that MyCollection.InnerList is not added to colFieldsInfo. Why
not?


InnerList is a property, not a field.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2

P: n/a
>>My problem is that MyCollection.InnerList is not added to colFieldsInfo.
Why
not?


InnerList is a property, not a field.


yes, but it doesn't add the fields _size, _version, _syncroot and _items of
CollectionBase either.

GetType.GetFields(BF.NonPublic, BF.Public, BF.Instance, BF.Static)
doesn't return any of the fields of the inherited class. Why not? And how
do I get those fields?

Thanks.
Nov 21 '05 #3

P: n/a
>yes, but it doesn't add the fields _size, _version, _syncroot and _items of
CollectionBase either.
You must be looking at a different version than I do. In v1.1 of the
framework CollectionBase only has a single private field, an ArrayList
called list.

GetType.GetFields(BF.NonPublic, BF.Public, BF.Instance, BF.Static)
doesn't return any of the fields of the inherited class. Why not?
It simply doesn't, not private fields.

And how do I get those fields?


Walk the inheritance chain and call GetFields on each base class.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.