public static TypeDescriptionProvider GetProvider (object instance) { if (instance == null) throw new ArgumentNullException ("instance"); TypeDescriptionProvider ret = null; lock (componentDescriptionProvidersLock) { LinkedList <TypeDescriptionProvider> plist; WeakObjectWrapper instanceWrapper = new WeakObjectWrapper (instance); if (componentDescriptionProviders.TryGetValue (instanceWrapper, out plist) && plist.Count > 0) ret = plist.Last.Value; instanceWrapper = null; } if (ret == null) ret = GetProvider (instance.GetType ()); if (ret == null) return new DefaultTypeDescriptionProvider (); else return new WrappedTypeDescriptionProvider (ret); }
public static void RemoveProvider (TypeDescriptionProvider provider, object instance) { if (provider == null) throw new ArgumentNullException ("provider"); if (instance == null) throw new ArgumentNullException ("instance"); //bool removed = false; lock (componentDescriptionProvidersLock) { LinkedList <TypeDescriptionProvider> plist; WeakObjectWrapper instanceWrapper = new WeakObjectWrapper (instance); if (componentDescriptionProviders.TryGetValue (instanceWrapper, out plist) && plist.Count > 0) { RemoveProvider (provider, plist); //removed = true; } instanceWrapper = null; } var refreshed = Refreshed; if (refreshed != null) refreshed (new RefreshEventArgs (instance)); }
public static void AddProvider (TypeDescriptionProvider provider, object instance) { if (provider == null) throw new ArgumentNullException ("provider"); if (instance == null) throw new ArgumentNullException ("instance"); lock (componentDescriptionProvidersLock) { LinkedList <TypeDescriptionProvider> plist; WeakObjectWrapper instanceWrapper = new WeakObjectWrapper (instance); if (!componentDescriptionProviders.TryGetValue (instanceWrapper, out plist)) { plist = new LinkedList <TypeDescriptionProvider> (); componentDescriptionProviders.Add (new WeakObjectWrapper (instance), plist); } plist.AddLast (provider); instanceWrapper = null; Refresh (instance); } }