//Get all non abstract derived types of base type in the current loaded assemplies public static List <TypeMetaInfo> GetTypeMetaDerivedFrom(Type baseType, bool getOld = true) { var infos = new List <TypeMetaInfo>(); foreach (var type in ReflectionTools.GetImplementationsOf(baseType)) { if (type.BaseType != baseType) { continue; } if (type.GetCustomAttributes(typeof(System.ObsoleteAttribute), true).FirstOrDefault() != null) { continue; } var nameAtt = type.GetCustomAttributes(typeof(NameAttribute), true).FirstOrDefault() as NameAttribute; if (getOld) { if (nameAtt != null && nameAtt.old) { var info = new TypeMetaInfo(); info.type = type; info.name = nameAtt != null ? nameAtt.name : type.Name.SplitCamelCase(); var attachAtt = type.GetCustomAttributes(typeof(AttachableAttribute), true).FirstOrDefault() as AttachableAttribute; if (attachAtt != null) { info.attachableTypes = attachAtt.types; } infos.Add(info); } } else { if (nameAtt != null && !nameAtt.old) { var info = new TypeMetaInfo(); info.type = type; info.name = nameAtt != null ? nameAtt.name : type.Name.SplitCamelCase(); var attachAtt = type.GetCustomAttributes(typeof(AttachableAttribute), true).FirstOrDefault() as AttachableAttribute; if (attachAtt != null) { info.attachableTypes = attachAtt.types; } infos.Add(info); } } } infos = infos.OrderBy(i => i.name).ToList(); return(infos); }
private static void Load(XmlMetaModel.NamespaceModel model) { string namespaceName = model.name; if (string.IsNullOrEmpty(namespaceName)) { throw new ArgumentException("namespace's name is empty"); } if (!string.IsNullOrEmpty(model.Name)) { if (namespaceMaps_.ContainsKey(namespaceName)) { throw new ArgumentException(namespaceName + " namespace map is already has"); } namespaceMaps_.Add(namespaceName, model.Name); } if (emitter_.BridgeTypes.IsNamespaceExists(model.name)) { if (model.Classes != null) { foreach (var classModel in model.Classes) { string className = classModel.name; if (string.IsNullOrEmpty(className)) { throw new ArgumentException(string.Format("namespace[{0}] has a class's name is empty", namespaceName)); } string keyName = namespaceName + '.' + className; FixName(ref keyName); var type = emitter_.BridgeTypes.GetOrDefault(keyName); if (type != null) { if (types_.ContainsKey(type.TypeDefinition)) { throw new ArgumentException(type.TypeDefinition.FullName + " is already has"); } TypeMetaInfo info = new TypeMetaInfo(type.TypeDefinition, classModel); types_.Add(info.TypeDefinition, info); } else { emitter_.Log.Warn(keyName + " is not found at BridgeTypes"); } } } } else { emitter_.Log.Info("namespace " + model.name + " is not load meta data xml"); } }
//Get all non abstract derived types of base type in the current loaded assemplies public static List <TypeMetaInfo> GetTypeMetaDerivedFrom(Type baseType) { var infos = new List <TypeMetaInfo>(); foreach (var type in ReflectionTools.GetDerivedTypesOf(baseType)) { if (type.GetCustomAttributes(typeof(System.ObsoleteAttribute), true).FirstOrDefault() != null) { continue; } var info = new TypeMetaInfo(); info.type = type; var nameAtt = type.GetCustomAttributes(typeof(NameAttribute), true).FirstOrDefault() as NameAttribute; info.name = nameAtt != null? nameAtt.name : type.Name.SplitCamelCase(); //如果反射的名字为空,则将type的名字作为名字 var catAtt = type.GetCustomAttributes(typeof(CategoryAttribute), true).FirstOrDefault() as CategoryAttribute; if (catAtt != null) { info.category = catAtt.category; } var attachAtt = type.GetCustomAttributes(typeof(AttachableAttribute), true).FirstOrDefault() as AttachableAttribute; if (attachAtt != null) { info.attachableTypes = attachAtt.types; } info.isUnique = type.GetCustomAttributes(typeof(UniqueElementAttribute), true).FirstOrDefault() as UniqueElementAttribute != null; infos.Add(info); } infos = infos.OrderBy(i => i.name).OrderBy(i => i.category).ToList(); return(infos); }