예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClassTypeTree"/> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="selfType">Type of the this node.</param>
        /// <param name="types">The possible child types.</param>
        protected ClassTypeTree(ClassTypeTree parent, Type selfType, IEnumerable <Type> types)
        {
            // ReSharper disable DoNotCallOverridableMethodsInConstructor

            _parent   = parent;
            _selfType = selfType;

            // Abort if this is a wildcard leaf
            if (selfType == null || types == null)
            {
                return;
            }

            // Take all types that are not this type, and that can be assigned from this type
            types = types.Where(x => x != selfType && _selfType.IsAssignableFrom(x));

            // Only take the types that cannot be assigned by the other child types, giving us only the immediate
            // children instead of ALL children
            var childTypes = types.Where(x => !types.Any(y => x != y && x.IsSubclassOf(y)));

            // Check if we have any children
            if (!childTypes.IsEmpty())
            {
                var childList = new List <ClassTypeTree>();

                // Recursively build the children
                foreach (var bt in childTypes)
                {
                    childList.Add(CreateNode(this, bt, types));
                }

                // Add the wildcard that will catch anything that does not fit the other children
                childList.Add(CreateNode(this, null, null));

                _children = FinalizeChildren(childList);
            }

            // ReSharper restore DoNotCallOverridableMethodsInConstructor
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClassTypeTree"/> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="selfType">Type of the this node.</param>
        /// <param name="types">The possible child types.</param>
        protected ClassTypeTree(ClassTypeTree parent, Type selfType, IEnumerable<Type> types)
        {
            // ReSharper disable DoNotCallOverridableMethodsInConstructor

            _parent = parent;
            _selfType = selfType;

            // Abort if this is a wildcard leaf
            if (selfType == null || types == null)
                return;

            // Take all types that are not this type, and that can be assigned from this type
            types = types.Where(x => x != selfType && _selfType.IsAssignableFrom(x));

            // Only take the types that cannot be assigned by the other child types, giving us only the immediate
            // children instead of ALL children
            var childTypes = types.Where(x => !types.Any(y => x != y && x.IsSubclassOf(y)));

            // Check if we have any children
            if (!childTypes.IsEmpty())
            {
                var childList = new List<ClassTypeTree>();

                // Recursively build the children
                foreach (var bt in childTypes)
                {
                    childList.Add(CreateNode(this, bt, types));
                }

                // Add the wildcard that will catch anything that does not fit the other children
                childList.Add(CreateNode(this, null, null));

                _children = FinalizeChildren(childList);
            }

            // ReSharper restore DoNotCallOverridableMethodsInConstructor
        }
예제 #3
0
 /// <summary>
 /// Creates a <see cref="ClassTypeTree"/> using the given values. This allows derived types of the
 /// <see cref="ClassTypeTree"/> to have their derived type be used for every node in the tree.
 /// </summary>
 /// <param name="parent">The parent node.</param>
 /// <param name="selfType">The type of this node.</param>
 /// <param name="types">All of the possible child nodes.</param>
 /// <returns>A <see cref="ClassTypeTree"/> using the given values.</returns>
 protected virtual ClassTypeTree CreateNode(ClassTypeTree parent, Type selfType, IEnumerable<Type> types)
 {
     return new ClassTypeTree(parent, selfType, types);
 }
예제 #4
0
 /// <summary>
 /// Creates a <see cref="ClassTypeTree"/> using the given values. This allows derived types of the
 /// <see cref="ClassTypeTree"/> to have their derived type be used for every node in the tree.
 /// </summary>
 /// <param name="parent">The parent node.</param>
 /// <param name="selfType">The type of this node.</param>
 /// <param name="types">All of the possible child nodes.</param>
 /// <returns>A <see cref="ClassTypeTree"/> using the given values.</returns>
 protected virtual ClassTypeTree CreateNode(ClassTypeTree parent, Type selfType, IEnumerable <Type> types)
 {
     return(new ClassTypeTree(parent, selfType, types));
 }