System.ComponentModel.TypeDescriptor.NodeFor C# (CSharp) Method

NodeFor() private static method

Retrieves the head type description node for a type. A head node pointing to a reflection based type description provider will be created on demand. If createDelegator is true, this method will create a delegation node for a type if the type has no node of its own. Delegation nodes should be created if you are going to hand this node out to a user. Without a delegation node, user code could skip providers that are added after their call. Delegation nodes solve that problem. If createDelegator is false, this method will recurse up the base type chain looking for nodes.
private static NodeFor ( Type type, bool createDelegator ) : TypeDescriptionNode
type System.Type
createDelegator bool
return TypeDescriptionNode
        private static TypeDescriptionNode NodeFor(Type type, bool createDelegator)
        {
            Debug.Assert(type != null, "Caller should validate");
            CheckDefaultProvider(type);

            // First, check our provider type table to see if we have a matching
            // provider for this type.  The provider type table is a cache that
            // matches types to providers.  When a new provider is added or
            // an existing one removed, the provider type table is torn
            // down and automatically rebuilt on demand.
            //
            TypeDescriptionNode node = null;
            Type searchType = type;

            while (node == null)
            {
                node = (TypeDescriptionNode)s_providerTypeTable[searchType];
                if (node == null)
                {
                    node = (TypeDescriptionNode)s_providerTable[searchType];
                }

                if (node == null)
                {
                    Type baseType = GetNodeForBaseType(searchType);

                    if (searchType == typeof(object) || baseType == null)
                    {
                        lock (s_providerTable)
                        {
                            node = (TypeDescriptionNode)s_providerTable[searchType];

                            if (node == null)
                            {
                                // The reflect type description provider is a default provider that
                                // can provide type information for all objects.
                                node = new TypeDescriptionNode(new ReflectTypeDescriptionProvider());
                                s_providerTable[searchType] = node;
                            }
                        }
                    }
                    else if (createDelegator)
                    {
                        node = new TypeDescriptionNode(new DelegatingTypeDescriptionProvider(baseType));
                        lock (s_providerTable)
                        {
                            s_providerTypeTable[searchType] = node;
                        }
                    }
                    else
                    {
                        // Continue our search
                        searchType = baseType;
                    }
                }
            }

            return node;
        }

Same methods

TypeDescriptor::NodeFor ( Type type ) : TypeDescriptionNode
TypeDescriptor::NodeFor ( object instance ) : TypeDescriptionNode
TypeDescriptor::NodeFor ( object instance, bool createDelegator ) : TypeDescriptionNode