C# – Type.GetFields() – only returning “public const” fields

.netc++reflection

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.

Best Solution

type.GetFields(BindingFlags.Static | BindingFlags.Public).Where(f => f.IsLiteral);