//------------------------------------------------------ // // Public Methods // //------------------------------------------------------ #region Public Methods /// <summary> /// Static method that returns a DependencyPropertyDescriptor from a PropertyDescriptor. /// </summary> public static DependencyPropertyDescriptor FromProperty(PropertyDescriptor property) { if (property == null) { throw new ArgumentNullException("property"); } DependencyPropertyDescriptor dpd; bool found; lock (_cache) { found = _cache.TryGetValue(property, out dpd); } if (found) { return(dpd); } // Locate the dependency property. We do this a fast way // by searching for InternalPropertyDescriptor, and a slow // way, by looking for an attribute. The fast way works unless // someone has added another layer of metadata overrides to // TypeDescriptor. DependencyProperty dp = null; bool isAttached = false; DependencyObjectPropertyDescriptor idpd = property as DependencyObjectPropertyDescriptor; if (idpd != null) { dp = idpd.DependencyProperty; isAttached = idpd.IsAttached; } else { #pragma warning suppress 6506 // property is obviously not null DependencyPropertyAttribute dpa = property.Attributes[typeof(DependencyPropertyAttribute)] as DependencyPropertyAttribute; if (dpa != null) { dp = dpa.DependencyProperty; isAttached = dpa.IsAttached; } } if (dp != null) { dpd = new DependencyPropertyDescriptor(property, property.Name, property.ComponentType, dp, isAttached); lock (_cache) { _cache[property] = dpd; } } return(dpd); }
public DependencyObjectProvider() : base(TypeDescriptor.GetProvider(typeof(DependencyObject))) { TypeDescriptor.Refreshed += delegate(RefreshEventArgs args) { if (args.TypeChanged != null && typeof(DependencyObject).IsAssignableFrom(args.TypeChanged)) { ClearCache(); DependencyObjectPropertyDescriptor.ClearCache(); DPCustomTypeDescriptor.ClearCache(); DependencyPropertyDescriptor.ClearCache(); } }; }