Beispiel #1
0
 /// <summary>
 /// Determines whether it has a specified attribute applied to it.
 /// </summary>
 public static bool Defines <TAttribute>(this MemberInfo member, bool inherit = true) where TAttribute : Attribute
 {
     return(member.IsDefined(typeof(TAttribute), inherit));
 }
Beispiel #2
0
 /// <summary>
 /// 检查指定指定类型成员中是否存在指定的Attribute特性
 /// </summary>
 /// <typeparam name="T">要检查的Attribute特性类型</typeparam>
 /// <param name="memberInfo">要检查的类型成员</param>
 /// <param name="inherit">是否从继承中查找</param>
 /// <returns>是否存在</returns>
 public static bool HasAttribute <T>(this MemberInfo memberInfo, bool inherit = true) where T : Attribute
 {
     return(memberInfo.IsDefined(typeof(T), inherit));
 }
Beispiel #3
0
 /// <summary>
 /// 检查指定指定类型成员中是否存在指定的Attribute特性
 /// </summary>
 /// <typeparam name="T">要检查的Attribute特性类型</typeparam>
 /// <param name="memberInfo">要检查的类型成员</param>
 /// <param name="inherit">是否从继承中查找</param>
 /// <returns>是否存在</returns>
 public static bool HasAttribute <T>(this MemberInfo memberInfo, bool inherit = false) where T : Attribute
 {
     return(memberInfo.IsDefined(typeof(T), inherit));
     //return memberInfo.GetCustomAttributes(typeof(T), inherit).Any(m => (m as T) != null);
 }