Ejemplo n.º 1
0
        internal static IEnumerable <Type> AncestorsAndSelf(Type type)
        {
            TypeTreeNode typeNode = _typeToNode[type];

            while (typeNode != null)
            {
                yield return(typeNode.Type);

                typeNode = typeNode.Parent;
            }
        }
Ejemplo n.º 2
0
 static TypeTree()
 {
     RootType = typeof(object);
     Root     = new TypeTreeNode(RootType);
     KnownTypes.Add(RootType);
     NodesByType.TryAdd(Root.Type, Root);
     NodesByName.TryAdd(Root.Type.Name, new ConcurrentBag <TypeTreeNode> {
         Root
     });
     // ReSharper disable once AssignNullToNotNullAttribute
     NodesByFullName.TryAdd(Root.Type.FullName, Root);
 }
Ejemplo n.º 3
0
 private static void BuildTypeTree(List <Type> types)
 {
     // One time pass through types to create initial node list.
     foreach (var type in types)
     {
         _typeToNode[type] = new TypeTreeNode(type);
     }
     // One more time to build the tree (adding child to parent).
     foreach (var type in _typeToNode.Keys)
     {
         if (_typeToNode.ContainsKey(type.BaseType))
         {
             // Found the parent so add child to parent.
             _typeToNode[type.BaseType].AddChild(_typeToNode[type]);
         }
         else
         {
             // If the base type is not found then it must be root.
             _root = _typeToNode[type];
         }
     }
 }
Ejemplo n.º 4
0
        internal static void AddToTypeTree(HashSet <Type> types)
        {
            types.ExceptWith(KnownTypes);
            if (types.Count < 1)
            {
                return;
            }
            lock (LoadLock) {
                foreach (var type in types)
                {
                    KnownTypes.Add(type);
                }

                var newTypes = new HashSet <Type>(types.Where(t => RootType.IsAssignableFrom(t)));
                var newNodes = new List <TypeTreeNode>(newTypes.Count);
                foreach (var type in newTypes)
                {
                    var node = new TypeTreeNode(type);
                    NodesByType.TryAdd(type, node);
                    if (!NodesByName.TryGetValue(type.Name, out var list))
                    {
                        list = new ConcurrentBag <TypeTreeNode>();
                        NodesByName.TryAdd(type.Name, list);
                    }
                    list.Add(node);

                    if (!string.IsNullOrWhiteSpace(type.FullName))
                    {
                        NodesByFullName.TryAdd(type.FullName, node);
                    }
                    newNodes.Add(node);
                }
                UpdateByLevel(new List <TypeTreeNode> {
                    Root
                }, newNodes);
            }
        }
Ejemplo n.º 5
0
 internal void AddChild(TypeTreeNode typeTreeNode)
 {
     typeTreeNode.Parent = this;
     Children.Add(typeTreeNode);
 }