views:

417

answers:

2

I want to call Type.GetFields() and only get back fields declared as "public const". I have this so far...

type.GetFields(BindingFlags.Static | BindingFlags.Public)

... but that also includes "public static" fields.

+4  A: 

Trying checking whether FieldInfo.Attributes includes FieldAttributes.Literal. I haven't checked it, but it sounds right...

(I don't think you can get only constants in a single call to GetFields, but you can filter the results returned that way.)

Jon Skeet
win!
Jon Kruger
+5  A: 
type.GetFields(BindingFlags.Static | BindingFlags.Public).Where(f => f.IsLiteral);
Thomas Levesque