System.Attribute.InternalIsDefined C# (CSharp) Method

InternalIsDefined() private static method

private static InternalIsDefined ( EventInfo element, Type attributeType, bool inherit ) : bool
element EventInfo
attributeType Type
inherit bool
return bool
        private static bool InternalIsDefined (EventInfo element, Type attributeType, bool inherit)
        {
            // walk up the hierarchy chain
            if (element.IsDefined(attributeType, inherit))
                return true;
            
            if (inherit)
            {
                AttributeUsageAttribute usage = InternalGetAttributeUsage(attributeType);

                if (!usage.Inherited) 
                    return false;

                EventInfo baseEvent = GetParentDefinition(element);

                while (baseEvent != null)
                {
                    if (baseEvent.IsDefined(attributeType, false))
                        return true;
                    baseEvent = GetParentDefinition(baseEvent);
                }
            }

            return false;
        }

Same methods

Attribute::InternalIsDefined ( PropertyInfo element, Type attributeType, bool inherit ) : bool

Usage Example

Beispiel #1
0
        public static bool IsDefined(MemberInfo element, Type attributeType, bool inherit)
        {
            if (element == (MemberInfo)null)
            {
                throw new ArgumentNullException("element");
            }
            if (attributeType == (Type)null)
            {
                throw new ArgumentNullException("attributeType");
            }
            if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
            }
            switch (element.MemberType)
            {
            case MemberTypes.Event:
                return(Attribute.InternalIsDefined((EventInfo)element, attributeType, inherit));

            case MemberTypes.Property:
                return(Attribute.InternalIsDefined((PropertyInfo)element, attributeType, inherit));

            default:
                return(element.IsDefined(attributeType, inherit));
            }
        }