📜  获取类 c# 代码示例中的常量列表

📅  最后修改于: 2022-03-11 14:48:53.101000             🧑  作者: Mango

代码示例1
public static class TypeUtilities
{
    public static List GetAllPublicConstantValues(this Type type)
    {
        return type
            .GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
            .Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType == typeof(T))
            .Select(x => (T)x.GetRawConstantValue())
            .ToList();
    }
}