473,394 Members | 1,714 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,394 software developers and data experts.

Reflection, GetFields, BindingFlags.

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
3 4805
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
>>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
>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James Hadwen | last post by:
Hi, I'm trying to do something with reflection that's a little wierd. The idea is that I call for a field to be updated on a base class. Using reflection it first updates the value, and then...
1
by: HarryZhao | last post by:
Hi, I'm using reflection and try to populate default value (ie. 0 for integer,'' for string,etc) to an unknow object based on give type. The following code is working only for two level of objects...
3
by: ChristianREMOVE.EitnerTHIS | last post by:
Hi people, I have a class which defines some "public static readonly string" fields. If I say FieldInfo fieldInfos = typeof(DaClass).GetFields(); these fields are reported by reflection,...
3
by: Oskar Lundgren | last post by:
I want to iterate over fields declared like this, using reflection (and there are good reasons for that): Protected WithEvents Foo1 As Bar Protected WithEvents Foo2 As Bar .... I use the...
0
by: Jeff Jarrell | last post by:
This is in a form. I want to use reflection to get an object instance. When i break it down a little differently, the me.getType returns ok. But the .GetField always returns nothing. So...
1
by: Stu | last post by:
Hi, I am trying to write a detailed logging system for a site. The client basically wants us to save the values of the properties on the page every time someone presses a save button. I have...
3
by: nam23 | last post by:
Hi, I'd like to create a List containing all the checkboxes on a form. The thing is, I don't know how many checkboxes there might be. I thought perhaps I could use reflection to look at all of...
3
by: bill | last post by:
All, I have the following: ...... unsafe public struct Example { public double we;
2
by: Torben Laursen | last post by:
I have a complicated class that I use to store a lot of values Now I need a copy of that class and I have been trying to find a way to do this automatic so I don't have to assign all properties and...
10
by: Rotsey | last post by:
Hi, I have a class that exist in my UI assembly that inherits from a class in a referenced assembly like this. class EmployeesDC { private string mstrEmployeeNumber; etc
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.