private void FillDisconnectedNodes() { List <Assembly> newAssemblies = AppDomain.CurrentDomain.GetAssemblies() .Where(a => !a.IsDynamic) .Where(a => !_scannedAssemblies.Contains(a.FullName)) .ToList(); IEnumerable <Assembly> referencingCore = newAssemblies .Where(a => a.GetReferencedAssemblies().Any(an => an.FullName == _aowClassAssemblyName)); foreach (Assembly assembly in referencingCore) { foreach (TypeInfo type in assembly.DefinedTypes) { AowClassAttribute aowClass = type.GetCustomAttribute <AowClassAttribute>(); if (aowClass != null) { InheritanceNode disconnectedNode = new InheritanceNode(type, aowClass); _disconnectedNodes.TryAdd(disconnectedNode.Type, disconnectedNode); } } } foreach (Assembly assembly in newAssemblies) { _scannedAssemblies.Add(assembly.FullName); } }
public void ConnectSubclass(InheritanceNode node) { node.BaseClass = this; DerivedClasses.Add(node); if (node.ClassID.HasValue) { DerivedClassLookup.Add(node.ClassID.Value, node); } }
public InheritanceNode FindSubclass(int subclassID) { InheritanceNode node = TryFindSubclass(subclassID); if (node == null) { throw new InvalidOperationException(String.Format("Type {0} doesn't have a derived class with ID = 0x{1:x8}", Type.Name, subclassID)); } return(node); }
private void Print(InheritanceNode node, StringBuilder builder, int depth) { for (int i = 0; i < depth; i++) { builder.Append(" "); } builder.AppendLine(node.ToString()); foreach (InheritanceNode subnode in node.DerivedClasses) { Print(subnode, builder, depth + 1); } }
private void ConnectNodes() { lock ( _lock ) { while (_disconnectedNodes.Count > 0) { InheritanceNode node = TakeDisconnectedNode(); if (node == null) { break; } ConnectNode(node); } } }
private void ConnectNode(InheritanceNode node) { foreach (InheritanceNode anotherNode in _cache.Values.Concat(_disconnectedNodes.Values)) { if (IsParent(anotherNode, node)) { anotherNode.ConnectSubclass(node); } if (IsParent(node, anotherNode)) { node.ConnectSubclass(anotherNode); } } _cache.TryAdd(node.Type, node); }
private bool IsGenericParent(InheritanceNode parent, InheritanceNode child) => parent.Type.IsGenericTypeDefinition && child.Type.BaseType.IsGenericType && child.Type.BaseType.GetGenericTypeDefinition() == parent.Type;
private bool IsParent(InheritanceNode parent, InheritanceNode child) => child.BaseClass == null && ( child.Type.BaseType == parent.Type || IsGenericParent(parent, child) );