CustomAttributeExtensions
using System.Collections.Generic;
namespace System.Reflection
{
internal static class CustomAttributeExtensions
{
public static IEnumerable<T> GetCustomAttributes<T>(this Assembly element) where T : Attribute
{
Attribute[] customAttributes = Attribute.GetCustomAttributes(element, typeof(T));
for (int i = 0; i < customAttributes.Length; i++) {
T val = (T)customAttributes[i];
yield return val;
}
}
public static IEnumerable<T> GetCustomAttributes<T>(this MemberInfo element, bool inherit) where T : Attribute
{
Attribute[] customAttributes = Attribute.GetCustomAttributes(element, typeof(T), inherit);
for (int i = 0; i < customAttributes.Length; i++) {
T val = (T)customAttributes[i];
yield return val;
}
}
public static bool IsDefined(this MemberInfo element, Type attributeType)
{
return Attribute.IsDefined(element, attributeType);
}
public static bool IsDefined(this ParameterInfo element, Type attributeType)
{
return Attribute.IsDefined(element, attributeType);
}
}
}