public void Init(Type type) { //遍历所有自定义属性 foreach (FieldInfo fi in type.GetFields()) { EditorEnumAttribute att = Attribute.GetCustomAttribute(fi, typeof(EditorEnumAttribute)) as EditorEnumAttribute; if (att == null) { continue; } int value = (int)fi.GetValue(null); var info = new EnumInfo { Display = att.Name, Value = value }; Enums.Add(info); } }
public static void InitErrorMsg() { hints = new Dictionary <int, string>( ); Type type = typeof(StrDef); foreach (FieldInfo fi in type.GetFields()) { EditorEnumAttribute att = Attribute.GetCustomAttribute(fi, typeof(EditorEnumAttribute)) as EditorEnumAttribute; if (att == null) { continue; } int index = (int)fi.GetValue(null); if (hints.ContainsKey(index)) { throw new Exception(string.Format("StrDef.InitErrorMsg error, index {0} has exists", index)); } hints[index] = att.Name; } }