/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public virtual void Execute(IPlan plan) { IEnumerable <MethodInfo> candidates = GetCandidateMethods(plan.Type); RegisterClassInterceptors(plan.Type, plan, candidates); foreach (MethodInfo method in candidates) { PropertyInfo property = method.GetPropertyFromMethod(plan.Type); ICustomAttributeProvider provider = (ICustomAttributeProvider)property ?? method; InterceptAttribute[] attributes = provider.GetAllAttributes <InterceptAttribute>(); if (attributes.Length == 0) { continue; } RegisterMethodInterceptors(plan.Type, method, attributes); // Indicate that instances of the type should be proxied. if (!plan.Has <ProxyDirective>()) { plan.Add(new ProxyDirective()); } } }
/// <summary> /// Determines whether the member is decorated with an attribute that matches the one provided. /// </summary> /// <typeparam name="T">The type of attribute to search for.</typeparam> /// <param name="member">The member to examine.</param> /// <param name="attributeToMatch">The attribute to match against.</param> /// <returns><see langword="True"/> if the member is decorated with a matching attribute, otherwise <see langword="false"/>.</returns> public static bool HasMatchingAttribute <T>(this ICustomAttributeProvider member, T attributeToMatch) where T : Attribute { T[] attributes = member.GetAllAttributes <T>(); if ((attributes == null) || (attributes.Length == 0)) { return(false); } return(attributes.Any(attribute => attribute.Match(attributeToMatch))); }
public static T[] GetAllAttributes <T>(this ICustomAttributeProvider member) #endif where T : Attribute { return(member.GetAllAttributes <T>(false)); }
/// <summary> /// 获取该成员上的其中一个特性 /// </summary> public static TAttribute GetSingleAttribute <TAttribute>(this ICustomAttributeProvider target, bool inherit) where TAttribute : Attribute { return(target.GetAllAttributes <TAttribute>(inherit).FirstOrDefault()); }