public void Initialize(Type enumType) { if (isInitialized) { return; } isInitialized = true; // to avoid to change placesGetValues, use GetFields var list = new List <int>(); var fields = enumType.GetFields(); //var iconBitmaps = new List<Bitmap>(); //bool hasIcon = false; foreach (var f in fields) { if (f.FieldType != enumType) { continue; } var attributes = f.GetCustomAttributes(false); object name = f.ToString(); var key = KeyAttribute.GetKey(attributes); var nameKey = key + "_Name"; if (string.IsNullOrEmpty(key)) { nameKey = f.FieldType.ToString() + "_" + f.ToString() + "_Name"; } if (MultiLanguageTextProvider.HasKey(nameKey)) { name = new MultiLanguageString(nameKey); } else { name = NameAttribute.GetName(attributes); if (name.ToString() == string.Empty) { name = f.ToString(); } //System.IO.File.AppendAllText("kv.csv", nameKey + "," + name.ToString() + "\r\n"); } var iconAttribute = IconAttribute.GetIcon(attributes); if (iconAttribute != null) { name = iconAttribute.code + name; } list.Add((int)f.GetValue(null)); FieldNames.Add(name); } enums = list.ToArray(); }
public static EditableValue Create(object o, System.Reflection.PropertyInfo info) { var ret = new EditableValue(); ret.Value = o; var p = info; var attributes = p.GetCustomAttributes(false); var undo = attributes.Where(_ => _.GetType() == typeof(UndoAttribute)).FirstOrDefault() as UndoAttribute; if (undo != null && !undo.Undo) { ret.IsUndoEnabled = false; } else { ret.IsUndoEnabled = true; } var shown = attributes.Where(_ => _.GetType() == typeof(ShownAttribute)).FirstOrDefault() as ShownAttribute; if (shown != null && !shown.Shown) { ret.IsShown = false; } var selector_attribute = (from a in attributes where a is Data.SelectorAttribute select a).FirstOrDefault() as Data.SelectorAttribute; if (selector_attribute != null) { ret.SelfSelectorID = selector_attribute.ID; } // collect selected values var selectedAttributes = attributes.OfType <Data.SelectedAttribute>(); if (selectedAttributes.Count() > 0) { if (selectedAttributes.Select(_ => _.ID).Distinct().Count() > 1) { throw new Exception("Same IDs are required."); } ret.TargetSelectorID = selectedAttributes.First().ID; ret.RequiredSelectorValues = selectedAttributes.Select(_ => _.Value).ToArray(); } var key = KeyAttribute.GetKey(attributes); var nameKey = key + "_Name"; if (string.IsNullOrEmpty(key)) { nameKey = info.ReflectedType.Name + "_" + info.Name + "_Name"; } if (MultiLanguageTextProvider.HasKey(nameKey)) { ret.Title = new MultiLanguageString(nameKey); } else { ret.Title = NameAttribute.GetName(attributes); //if (!string.IsNullOrEmpty(ret.Title.ToString())) //{ // System.IO.File.AppendAllText("kv.csv", nameKey + "," + "\"" + ret.Title.ToString() + "\"" + "\r\n"); //} } var descKey = key + "_Desc"; if (string.IsNullOrEmpty(key)) { descKey = info.ReflectedType.Name + "_" + info.Name + "_Desc"; } if (MultiLanguageTextProvider.HasKey(descKey)) { ret.Description = new MultiLanguageString(descKey); } else { ret.Description = DescriptionAttribute.GetDescription(attributes); //if(!string.IsNullOrEmpty(ret.Description.ToString())) //{ // System.IO.File.AppendAllText("kv.csv", descKey + "," + "\"" + ret.Description.ToString() + "\"" + "\r\n"); //} } var treeNode = attributes.OfType <TreeNodeAttribute>().FirstOrDefault(); if (treeNode != null) { ret.TreeNodeID = treeNode.id; if (MultiLanguageTextProvider.HasKey(treeNode.key)) { ret.Title = new MultiLanguageString(treeNode.key); } } return(ret); }