2 using System.Collections.Generic;
8 public static class MethodInfoExtensions
10 public static bool HasAttribute(
this MethodInfo I, Type AttributeType)
12 if (!AttributeType.IsAbstract && typeof(Attribute).IsAssignableFrom(AttributeType))
14 foreach (
object attribute
in I.GetCustomAttributes(
true))
16 if (attribute.GetType() == AttributeType)
25 throw new Exception(
"{0} is not a attribute");
29 public static AttributeType GetAttribute<AttributeType> (
this MethodInfo I) where AttributeType:Attribute
31 if (!typeof(AttributeType).IsAbstract)
33 return (AttributeType)I.GetCustomAttributes(typeof(AttributeType),
true).FirstOrDefault();
37 throw new Exception(
"{0} is abstract");