我想调用Type.GetFields(),只返回声明为“public const”的字段。到目前为止我有这个...
type.GetFields(BindingFlags.Static | BindingFlags.Public)
...但其中还包括“公共(public)静态”字段。
最佳答案
尝试检查 FieldInfo.Attributes
是否包括 FieldAttributes.Literal
。我没有检查过,但是听起来不错...
(我认为您无法在对GetFields
的单次调用中仅获得常量,但可以过滤以这种方式返回的结果。)