Public Static Readonly Fields and Reflection

  • Thread starter ChristianREMOVE.EitnerTHIS
  • Start date
C

ChristianREMOVE.EitnerTHIS

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, whereas with

fieldInfos = typeof(DaClass).GetFields(BindingFlags.Static);

they are not given. So what's the matter here? Aren't the fields "real"
static fields or what?

Thanks for your consideration,

Christian
 
A

Alexander Shirshov

Christian,

You need to tell that you want public fields:

GetFields(BindingFlags.Static | BindingFlags.Public)

HTH,

Alexander Shirshov
 
C

ChristianREMOVE.EitnerTHIS

Dear Alexander,

A little look with Reflector and now it all seems so logical :)

Thank you,

Christian
 
A

Alexander Shirshov

I heard someone calling Reflector "less ambiguous .NET Framework
documentation" :)
 

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

Top