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.
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.
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.)
type.GetFields(BindingFlags.Static | BindingFlags.Public).Where(f => f.IsLiteral);