Reflection, GetFields, BindingFlags.

  • Thread starter Thread starter Trewq
  • Start date Start date
T

Trewq

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.
 
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
 
My problem is that MyCollection.InnerList is not added to colFieldsInfo.
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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top