示例#1
0
 public MeteringModeDescriptionAttribute(IntegralProviderType type, string description)
 {
     IntegralProviderType = type;
     Description          = description;
 }
示例#2
0
        public static IDictionary <int, string> GetMeteringModeDescriptionAttributeTitleAndValue(IntegralProviderType integralProviderType)
        {
            var dict     = new Dictionary <int, string>();
            var enumType = typeof(MeteringMode);
            var values   = Enum.GetValues(enumType);

            foreach (var value in values)
            {
                string name = Enum.GetName(enumType, value);
                if (name != null)
                {
                    // 获取枚举字段。
                    FieldInfo fieldInfo = enumType.GetField(name);
                    if (fieldInfo != null)
                    {
                        // 获取描述的属性。
                        Attribute[] attrs = Attribute.GetCustomAttributes(fieldInfo,
                                                                          typeof(MeteringModeDescriptionAttribute), false);
                        var attr = attrs.FirstOrDefault(o => (((MeteringModeDescriptionAttribute)o).IntegralProviderType & integralProviderType) == integralProviderType);
                        if (attr != null)
                        {
                            dict.Add((int)value, ((MeteringModeDescriptionAttribute)attr).Description);
                        }
                    }
                }
            }
            return(dict);
        }