/// <summary> /// recursively collects all extending classes /// </summary> /// <param name="ts"></param> private static void CollectAllExtendingClasses(TypeStore ts, SafeSet <TypeDefinition> extendingClasses) { if (extendingClasses.Contains(ts.Type)) { return; } foreach (var innerts in ts.ExtendingTypes) { if (!innerts.Type.IsAbstract && !innerts.Type.IsInterface) { extendingClasses.Add(innerts.Type); } CollectAllExtendingClasses(innerts, extendingClasses); } }
/// <summary> /// Loads all inheritance hierarchies in the current library /// into TypeDictionary in the form of a tree suitable for traversal. /// </summary> public void LoadInheritanceHierarchies() { if (isInheritanceHierarchyLoaded) return; isInheritanceHierarchyLoaded = true; AssemblyEx currAssembly = this.Services.CurrentAssembly.Assembly.Assembly; foreach (var tdef in currAssembly.TypeDefinitions) { TypeStore currTypeStore; if (!this.TypeDictionary.TryGetValue(tdef, out currTypeStore)) { currTypeStore = new TypeStore(tdef); this.TypeDictionary.Add(tdef, currTypeStore); } var baseType = tdef.BaseTypeDefinition; //This restricts our implementation to a single assembly for time being. if (baseType != null && baseType.Module.Assembly == currAssembly) { TypeStore baseTypeStore; if (!this.TypeDictionary.TryGetValue(baseType, out baseTypeStore)) { baseTypeStore = new TypeStore(baseType); this.TypeDictionary.Add(baseType, baseTypeStore); } baseTypeStore.ExtendingTypes.Add(currTypeStore); } try { var typeEx = tdef.Instantiate(MethodOrFieldAnalyzer.GetGenericTypeParameters(this, tdef)); if (typeEx != null) { foreach (var ifTypeEx in typeEx.DeclaredInterfaces) { var parentIfDef = ifTypeEx.Definition; if (parentIfDef.Module.Assembly != currAssembly) continue; TypeStore ifTypeStore; if (!this.TypeDictionary.TryGetValue(parentIfDef, out ifTypeStore)) { ifTypeStore = new TypeStore(parentIfDef); this.TypeDictionary.Add(parentIfDef, ifTypeStore); } ifTypeStore.ExtendingTypes.Add(currTypeStore); } } } catch (Exception ex) { this.Log.LogWarningFromException(ex, WikiTopics.MissingWikiTopic, "InheritanceLoader", "Failed to instantiate class " + tdef.FullName.ToString()); } } }
/// <summary> /// recursively collects all extending classes /// </summary> /// <param name="ts"></param> private static void CollectAllExtendingClasses(TypeStore ts, SafeSet<TypeDefinition> extendingClasses) { if (extendingClasses.Contains(ts.Type)) return; foreach (var innerts in ts.ExtendingTypes) { if (!innerts.Type.IsAbstract && !innerts.Type.IsInterface) extendingClasses.Add(innerts.Type); CollectAllExtendingClasses(innerts, extendingClasses); } }