internal static List <ArgHook> GetHooks(this MemberInfo member, Func <ArgHook, int> priority) { var hooks = member.Attrs <ArgHook>(); hooks = hooks.OrderByDescending(priority).ToList(); return(hooks); }
/// <summary> /// Gets the attribute of the given type or null if the member does not have this attribute defined. The standard reflection helper GetCustomAttributes will /// give you a new instance of the attribute every time you call it. This helper caches it's results so if you ask for the same attibute twice you will actually /// get back the same attribute. Note that the cache key is based off of the type T that you provide. So asking for Attr() where T : BaseType> and then asking for Attr() where T : ConcreteType /// will result in two different objects being returned. If you ask for Attr() where T : BaseType and then Attr() where T :BaseType the caching will work and you'll get the same object back /// the second time. /// </summary> /// <typeparam name="T">The type of attribute to search for</typeparam> /// <param name="info">The member to inspect</param> /// <returns>The desired attribute or null if it is not present</returns> public static T Attr <T>(this MemberInfo info) { if (info.HasAttr <T>()) { return(info.Attrs <T>()[0]); } else { return(default(T)); } }
/// <summary> /// Returns true if the given member has an attribute of the given type (including inherited types). /// </summary> /// <typeparam name="T">The type of attribute to test for (will return true for attributes that inherit from this type)</typeparam> /// <param name="info">The member to test</param> /// <returns>true if a matching attribute was found, false otherwise</returns> public static bool HasAttr <T>(this MemberInfo info) { return(info.Attrs <T>().Count > 0); }
internal static T GetHook <T>(this MemberInfo prop) where T : ArgHook { return((T)(from h in prop.Attrs <ArgHook>() where h.GetType() == typeof(T) select h).FirstOrDefault()); }