Type.GetFields() - only returning “public const” fields

前端 未结 2 1840
渐次进展
渐次进展 2021-02-11 21:02

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.P         


        
相关标签:
2条回答
  • 2021-02-11 21:30
    type.GetFields(BindingFlags.Static | BindingFlags.Public).Where(f => f.IsLiteral);
    
    0 讨论(0)
  • 2021-02-11 21:32

    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.)

    0 讨论(0)
提交回复
热议问题