Public Static Readonly Fields and Reflection

  • Thread starter Thread starter ChristianREMOVE.EitnerTHIS
  • Start date 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
 
Christian,

You need to tell that you want public fields:

GetFields(BindingFlags.Static | BindingFlags.Public)

HTH,

Alexander Shirshov
 
Dear Alexander,

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

Thank you,

Christian
 
I heard someone calling Reflector "less ambiguous .NET Framework
documentation" :-)
 
Back
Top