Why is Attributes.IsDefined() missing overloads?

Posted by Hans Passant on Stack Overflow See other posts from Stack Overflow or by Hans Passant
Published on 2010-06-11T21:37:25Z Indexed on 2010/06/11 21:42 UTC
Read the original article Hit count: 171

Filed under:
|
|

Inspired by an SO question. The Attribute class has several overloads for the IsDefined() method. Covered are attributes applied to Assembly, Module, MemberInfo, ParameterInfo. The MemberInfo overload covers PropertyInfo, FieldInfo, EventInfo, MethodInfo, ConstructorInfo.

That takes care of most of the AttributeTargets. Except for one biggy: there is no overload for Attribute.IsDefined(Type, Type) so that you could check if an attribute is defined on a class. Or a struct, delegate or enum for that matter.

Not that this is a real problem, Type.GetCustomAttributes() can fix that. But all of the BlahInfo types have this too. I wonder at the lack of symmetry. I can't put a finger on why this would be problem for Type. Guessing at an inheritance problem doesn't explain it to me. Having ValueType in the mix might be a lead, still doesn't make sense. I don't buy "they forgot", they never do.

Why is this overload missing?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET