private static AttributeUsageAttribute RetrieveAttributeUsage (Type attributeType)
{
if (attributeType == typeof (AttributeUsageAttribute))
/* Avoid endless recursion */
return new AttributeUsageAttribute (AttributeTargets.Class);
AttributeUsageAttribute usageAttribute = null;
object[] attribs = GetCustomAttributes (attributeType,
MonoCustomAttrs.AttributeUsageType, false);
if (attribs.Length == 0)
{
// if no AttributeUsage was defined on the attribute level, then
// try to retrieve if from its base type
if (attributeType.BaseType != null)
{
usageAttribute = RetrieveAttributeUsage (attributeType.BaseType);
}
if (usageAttribute != null)
{
// return AttributeUsage of base class
return usageAttribute;
}
// return default AttributeUsageAttribute if no AttributeUsage
// was defined on attribute, or its base class
return DefaultAttributeUsage;
}
// check if more than one AttributeUsageAttribute has been specified
// on the type
// NOTE: compilers should prevent this, but that doesn't prevent
// anyone from using IL ofcourse
if (attribs.Length > 1)
{
throw new FormatException ("Duplicate AttributeUsageAttribute cannot be specified on an attribute type.");
}
return ((AttributeUsageAttribute) attribs[0]);
}