public static void AddTypeItem(List <string> path, ObservableCollection <TypeItem> typeItems, TypeItem item) { var currentPathName = path[0]; path.RemoveAt(0); if (path.Count == 0) { typeItems.Add(item); } else { bool find = false; foreach (var itm in typeItems) { if (itm.TypeName == currentPathName) { find = true; AddTypeItem(path, itm.ChildList, item); break; } } if (!find) { var parentItem = new TypeItem(); parentItem.TypeName = currentPathName; typeItems.Add(parentItem); AddTypeItem(path, parentItem.ChildList, item); } } }
public static TypeItem CreateTypeItem(Type type, ImageSource icon, string typename = null) { var retVal = new TypeItem() { Type = type, TypeIcon = icon, }; if (typename == null) { retVal.TypeName = type.Name; } else { retVal.TypeName = typename; } return(retVal); }
void InitializeTypes() { mTypeItems.Clear(); if (PropertyType == null) { return; } ShowCreateOrReplaceBtn = Visibility.Visible; // null var item = TypeItem.CreateTypeItem(null, TryFindResource("Icon_Pill") as ImageSource, "null"); TypeItem.AddTypeItem(new List <string>() { "null" }, mTypeItems, item); var baseType = PropertyType; var assemblies = EngineNS.Rtti.RttiHelper.GetAnalyseAssemblys(EngineNS.ECSType.All); foreach (var assembly in assemblies) { var types = assembly.GetTypes(); foreach (var typeObj in types) { var type = typeObj as Type; if (type.Name.Contains("<")) { continue; } if (type.Name.Contains("=")) { continue; } if (type != baseType) { if (baseType.IsInterface) { if (type.GetInterface(baseType.FullName) == null) { continue; } } else if (!type.IsSubclassOf(baseType)) { continue; } } var cons = type.GetConstructor(Type.EmptyTypes); // 只能显示有默认构造函数的类型 if (cons == null) { continue; } List <string> path = new List <string>() { type.Name }; var nameAtts = type.GetCustomAttributes(typeof(EngineNS.Editor.Editor_ClassDisplayNameAttribute), false); if (nameAtts.Length > 0) { var nameAtt = nameAtts[0] as EngineNS.Editor.Editor_ClassDisplayNameAttribute; if (nameAtt.DisplayName != null) { path = new List <string>(nameAtt.DisplayName); } } else { path = new List <string>(type.FullName.Split('.')); } item = TypeItem.CreateTypeItem(type, TryFindResource("Icon_Pill") as ImageSource); TypeItem.AddTypeItem(path, mTypeItems, item); } } TreeView_Types.ItemsSource = mTypeItems; }
void InitializeTypes() { if (mCurChheckType == VarType && mTypeItems.Count != 0) { return; } mTypeItems.Clear(); Type baseType = null; var filter = EngineNS.Editor.Editor_TypeFilterAttribute.enTypeFilter.Unknow; var macrossType = EngineNS.Editor.Editor_MacrossClassAttribute.enMacrossType.None; if (BindProperty != null) { foreach (var att in BindProperty.Attributes) { if (att is EngineNS.Editor.Editor_TypeFilterAttribute) { var tempAtt = (EngineNS.Editor.Editor_TypeFilterAttribute)att; baseType = tempAtt.BaseType; filter = tempAtt.Filter; macrossType = tempAtt.MacrossType; } } } if (EngineNS.Editor.Editor_TypeFilterAttribute.Contains(filter, EngineNS.Editor.Editor_TypeFilterAttribute.enTypeFilter.Primitive)) { foreach (var type in mGeneralTypes) { if (baseType != null) { if (type != baseType) { if (baseType.IsInterface) { if (type.GetInterface(baseType.FullName) == null) { continue; } } else if (!type.IsSubclassOf(baseType)) { continue; } } } var item = TypeItem.CreateTypeItem(type, TryFindResource("Icon_Pill") as ImageSource); mTypeItems.Add(item); } } var assemblies = EngineNS.Rtti.RttiHelper.GetAnalyseAssemblys(CSType); foreach (var assembly in assemblies) { var types = assembly.GetTypes(); foreach (var typeObj in types) { var type = typeObj as Type; if (type.Name.Contains("<")) { continue; } if (type.Name.Contains("=")) { continue; } if (!(EngineNS.Editor.Editor_TypeFilterAttribute.Contains(filter, EngineNS.Editor.Editor_TypeFilterAttribute.enTypeFilter.Class) && type.IsClass) && !(EngineNS.Editor.Editor_TypeFilterAttribute.Contains(filter, EngineNS.Editor.Editor_TypeFilterAttribute.enTypeFilter.Struct) && type.IsValueType) && !(EngineNS.Editor.Editor_TypeFilterAttribute.Contains(filter, EngineNS.Editor.Editor_TypeFilterAttribute.enTypeFilter.Enum) && type.IsEnum)) { continue; } if (baseType != null) { if (type != baseType) { if (baseType.IsInterface) { if (type.GetInterface(baseType.FullName) == null) { continue; } } else if (!type.IsSubclassOf(baseType)) { continue; } } } if (macrossType != EngineNS.Editor.Editor_MacrossClassAttribute.enMacrossType.None) { var mtAtts = type.GetCustomAttributes(typeof(EngineNS.Editor.Editor_MacrossClassAttribute), false); if (mtAtts.Length == 0) { continue; } var att = mtAtts[0] as EngineNS.Editor.Editor_MacrossClassAttribute; if (!att.HasType(macrossType)) { continue; } } List <string> path = new List <string>() { type.Name }; var nameAtts = type.GetCustomAttributes(typeof(EngineNS.Editor.Editor_ClassDisplayNameAttribute), false); if (nameAtts.Length > 0) { var nameAtt = nameAtts[0] as EngineNS.Editor.Editor_ClassDisplayNameAttribute; if (nameAtt.DisplayName != null) { path = new List <string>(nameAtt.DisplayName); } } else { path = new List <string>(type.FullName.Split('.')); } var item = TypeItem.CreateTypeItem(type, TryFindResource("Icon_Pill") as ImageSource); TypeItem.AddTypeItem(path, mTypeItems, item); } } TreeView_Types.ItemsSource = mTypeItems; }