System.Attribute.InternalGetAttributeUsage C# (CSharp) Method

InternalGetAttributeUsage() private static method

private static InternalGetAttributeUsage ( Type type ) : AttributeUsageAttribute
type Type
return AttributeUsageAttribute
        private static AttributeUsageAttribute InternalGetAttributeUsage(Type type)
        {
            // Check if the custom attributes is Inheritable
            Object [] obj = type.GetCustomAttributes(typeof(AttributeUsageAttribute), false); 

            if (obj.Length == 1)
                return (AttributeUsageAttribute)obj[0];

            if (obj.Length == 0)
                return AttributeUsageAttribute.Default;

            throw new FormatException(String.Format(CultureInfo.CurrentCulture, 
                Environment.GetResourceString("Format_AttributeUsage"), type));
        }

Usage Example

Beispiel #1
0
        private static bool InternalParamIsDefined(MethodInfo method, ParameterInfo param, Type type, bool inherit)
        {
            if (param.IsDefined(type, false))
            {
                return(true);
            }
            if (method.DeclaringType == null || !inherit)
            {
                return(false);
            }
            int position = param.Position;

            for (method = method.GetParentDefinition(); method != null; method = method.GetParentDefinition())
            {
                param = method.GetParameters()[position];
                object[] customAttributes = param.GetCustomAttributes(type, false);
                for (int index = 0; index < customAttributes.Length; ++index)
                {
                    AttributeUsageAttribute attributeUsage = Attribute.InternalGetAttributeUsage(customAttributes[index].GetType());
                    if (customAttributes[index] is Attribute && attributeUsage.Inherited)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
All Usage Examples Of System.Attribute::InternalGetAttributeUsage