private void LazyFillOutBrowsableInfo()
 {
     foreach (CustomAttributeData customAttributeData in (IEnumerable <CustomAttributeData>) this.GetMethodInfo.GetCustomAttributesData())
     {
         if (customAttributeData.Constructor.DeclaringType.FullName.Equals(typeof(AttachedPropertyBrowsableForChildrenAttribute).FullName, StringComparison.Ordinal))
         {
             AttachedPropertyBrowsableForChildrenAttribute[] childrenAttributeArray = (AttachedPropertyBrowsableForChildrenAttribute[])this.runtimeGetMethodInfo.GetCustomAttributes(typeof(AttachedPropertyBrowsableForChildrenAttribute), false);
             AttachedPropertyBrowsableForChildrenAttribute   childrenAttribute      = childrenAttributeArray.Length != 0 ? childrenAttributeArray[0] : (AttachedPropertyBrowsableForChildrenAttribute)null;
             if (childrenAttribute != null)
             {
                 if (childrenAttribute.IncludeDescendants)
                 {
                     this.browsableFlags = AttachedPropertyMetadata.BrowsableFlags.AllDescendants;
                 }
                 else
                 {
                     this.browsableFlags |= AttachedPropertyMetadata.BrowsableFlags.Children;
                 }
             }
         }
         else if (customAttributeData.Constructor.DeclaringType.FullName.Equals(typeof(AttachedPropertyBrowsableForTypeAttribute).FullName, StringComparison.Ordinal))
         {
             AttachedPropertyBrowsableForTypeAttribute[] forTypeAttributeArray = (AttachedPropertyBrowsableForTypeAttribute[])this.runtimeGetMethodInfo.GetCustomAttributes(typeof(AttachedPropertyBrowsableForTypeAttribute), false);
             AttachedPropertyBrowsableForTypeAttribute   forTypeAttribute      = forTypeAttributeArray.Length != 0 ? forTypeAttributeArray[0] : (AttachedPropertyBrowsableForTypeAttribute)null;
             if (forTypeAttribute != null)
             {
                 this.browsableTargetType = forTypeAttribute.TargetType;
             }
         }
         else if (customAttributeData.Constructor.DeclaringType.FullName.Equals(typeof(AttachedPropertyBrowsableWhenAttributePresentAttribute).FullName, StringComparison.Ordinal))
         {
             AttachedPropertyBrowsableWhenAttributePresentAttribute[] presentAttributeArray = (AttachedPropertyBrowsableWhenAttributePresentAttribute[])this.runtimeGetMethodInfo.GetCustomAttributes(typeof(AttachedPropertyBrowsableWhenAttributePresentAttribute), false);
             AttachedPropertyBrowsableWhenAttributePresentAttribute   presentAttribute      = presentAttributeArray.Length != 0 ? presentAttributeArray[0] : (AttachedPropertyBrowsableWhenAttributePresentAttribute)null;
             if (presentAttribute != null)
             {
                 this.browsableFlags |= AttachedPropertyMetadata.BrowsableFlags.AttributePresent;
                 this.browsableAttributePresentType = presentAttribute.AttributeType;
             }
         }
     }
 }
        public bool Filter(PropertyDescriptor property)
        {
            if (this.element == null)
            {
                return(true);
            }

            // Filter the 20 stylistic set properties that I've never seen used.
            if (property.Name.Contains("Typography.StylisticSet"))
            {
                return(false);
            }

            AttachedPropertyBrowsableForChildrenAttribute          attachedPropertyForChildren  = (AttachedPropertyBrowsableForChildrenAttribute)property.Attributes[typeof(AttachedPropertyBrowsableForChildrenAttribute)];
            AttachedPropertyBrowsableForTypeAttribute              attachedPropertyForType      = (AttachedPropertyBrowsableForTypeAttribute)property.Attributes[typeof(AttachedPropertyBrowsableForTypeAttribute)];
            AttachedPropertyBrowsableWhenAttributePresentAttribute attachedPropertyForAttribute = (AttachedPropertyBrowsableWhenAttributePresentAttribute)property.Attributes[typeof(AttachedPropertyBrowsableWhenAttributePresentAttribute)];

            if (attachedPropertyForChildren != null)
            {
                DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(property);
                if (dpd == null)
                {
                    return(false);
                }

                FrameworkElement element = this.element;
                do
                {
                    element = element.Parent as FrameworkElement;
                    if (element != null && dpd.DependencyProperty.OwnerType.IsInstanceOfType(element))
                    {
                        return(true);
                    }
                }while (attachedPropertyForChildren.IncludeDescendants && element != null);
                return(false);
            }
            else if (attachedPropertyForType != null)
            {
                // when using [AttachedPropertyBrowsableForType(typeof(IMyInterface))] and IMyInterface is not a DependencyObject, Snoop crashes.
                // see http://snoopwpf.codeplex.com/workitem/6712

                if (attachedPropertyForType.TargetType.IsSubclassOf(typeof(DependencyObject)))
                {
                    DependencyObjectType doType = DependencyObjectType.FromSystemType(attachedPropertyForType.TargetType);
                    if (doType != null && doType.IsInstanceOfType(this.element))
                    {
                        return(true);
                    }
                }

                return(false);
            }
            else if (attachedPropertyForAttribute != null)
            {
                Attribute dependentAttribute = TypeDescriptor.GetAttributes(this.target)[attachedPropertyForAttribute.AttributeType];
                if (dependentAttribute != null)
                {
                    return(!dependentAttribute.IsDefaultAttribute());
                }
                return(false);
            }

            return(true);
        }