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

Refresh() public static method

Clears the properties and events for the specified module from the cache.
public static Refresh ( Module module ) : void
module System.Reflection.Module
return void
        public static void Refresh(Module module)
        {
            if (module == null)
            {
                Debug.Fail("COMPAT:  Returning, but you should not pass null here");
                return;
            }

            // Build up a list of type description providers for
            // each type that is a derived type of the given
            // object.  We will invalidate the metadata at
            // each of these levels.
            Hashtable refreshedTypes = null;

            lock (s_providerTable)
            {
                // Manual use of IDictionaryEnumerator instead of foreach to avoid DictionaryEntry box allocations.
                IDictionaryEnumerator e = s_providerTable.GetEnumerator();
                while (e.MoveNext())
                {
                    DictionaryEntry de = e.Entry;
                    Type nodeType = de.Key as Type;
                    if (nodeType != null && nodeType.GetTypeInfo().Module.Equals(module) || nodeType == typeof(object))
                    {
                        TypeDescriptionNode node = (TypeDescriptionNode)de.Value;
                        while (node != null && !(node.Provider is ReflectTypeDescriptionProvider))
                        {
                            if (refreshedTypes == null)
                            {
                                refreshedTypes = new Hashtable();
                            }
                            refreshedTypes[nodeType] = nodeType;
                            node = node.Next;
                        }

                        if (node != null)
                        {
                            ReflectTypeDescriptionProvider provider = (ReflectTypeDescriptionProvider)node.Provider;
                            Type[] populatedTypes = provider.GetPopulatedTypes(module);

                            foreach (Type populatedType in populatedTypes)
                            {
                                provider.Refresh(populatedType);
                                if (refreshedTypes == null)
                                {
                                    refreshedTypes = new Hashtable();
                                }
                                refreshedTypes[populatedType] = populatedType;
                            }
                        }
                    }
                }
            }

            // And raise the event if types were refresh and handlers are attached.
            //
            if (refreshedTypes != null && Refreshed != null)
            {
                foreach (Type t in refreshedTypes.Keys)
                {
                    RaiseRefresh(t);
                }
            }
        }

Same methods

TypeDescriptor::Refresh ( Assembly assembly ) : void
TypeDescriptor::Refresh ( Type type ) : void
TypeDescriptor::Refresh ( object component ) : void
TypeDescriptor::Refresh ( object component, bool refreshReflectionProvider ) : void

Usage Example

        public static void ClearCache(Type[]?types)
        {
            // ReflectTypeDescriptionProvider maintains global caches on top of reflection.
            // Clear those.
            ReflectTypeDescriptionProvider.ClearReflectionCaches();

            // Each type descriptor may also cache reflection-based state that it gathered
            // from ReflectTypeDescriptionProvider.  Clear those as well.
            if (types is not null)
            {
                foreach (Type type in types)
                {
                    TypeDescriptor.Refresh(type);
                }
            }
            else
            {
                foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    TypeDescriptor.Refresh(assembly);
                }
            }
        }