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

NodeFor() private static method

Retrieves the head type description node for an instance. Instance-based node lists are rare. If a node list is not available for a given instance, this will return the head node for the instance's type. This variation offers a bool called createDelegator. If true and there is no node list for this instance, NodeFor will create a temporary "delegator node" that, when queried, will delegate to the type stored in the instance. This is done on demand, which means if someone else added a type description provider for the instance's type the delegator would pick up the new type. If a query is being made that does not involve publicly exposing the type description provider for the instance, the query should pass in fase (the default) for createDelegator because no object will be created.
private static NodeFor ( object instance, bool createDelegator ) : TypeDescriptionNode
instance object
createDelegator bool
return TypeDescriptionNode
        private static TypeDescriptionNode NodeFor(object instance, bool createDelegator)
        {
            // For object instances, the provider cache key is not the object (that
            // would keep it in memory).  Instead, it is a subclass of WeakReference
            // that overrides GetHashCode and Equals to make it appear to be the
            // object it is wrapping.  A GC'd object causes WeakReference to return
            // false for all .Equals, but it always returns a valid hash code.

            Debug.Assert(instance != null, "Caller should validate");

            TypeDescriptionNode node = (TypeDescriptionNode)s_providerTable[instance];
            if (node == null)
            {
                Type type = instance.GetType();

                if (createDelegator)
                {
                    node = new TypeDescriptionNode(new DelegatingTypeDescriptionProvider(type));
                }
                else
                {
                    node = NodeFor(type);
                }
            }

            return node;
        }

Same methods

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