예제 #1
0
        private static List <MethodInfo> RunSelectionFilters(ControllerContext controllerContext, List <MethodInfo> methodInfos)
        {
            // remove all methods which are opting out of this request
            // to opt out, at least one attribute defined on the method must return false

            List <MethodInfo> matchesWithSelectionAttributes    = new List <MethodInfo>();
            List <MethodInfo> matchesWithoutSelectionAttributes = new List <MethodInfo>();

            foreach (MethodInfo methodInfo in methodInfos)
            {
                ICollection <ActionMethodSelectorAttribute> attrs = ReflectedAttributeCache.GetActionMethodSelectorAttributes(methodInfo);
                if (attrs.Count == 0)
                {
                    matchesWithoutSelectionAttributes.Add(methodInfo);
                }
                else if (attrs.All(attr => attr.IsValidForRequest(controllerContext, methodInfo)))
                {
                    matchesWithSelectionAttributes.Add(methodInfo);
                }
            }

            // if a matching action method had a selection attribute, consider it more specific than a matching action method
            // without a selection attribute
            return((matchesWithSelectionAttributes.Count > 0) ? matchesWithSelectionAttributes : matchesWithoutSelectionAttributes);
        }
 public override IEnumerable <FilterAttribute> GetFilterAttributes(bool useCache)
 {
     if (useCache && GetType() == typeof(TaskAsyncActionDescriptor))
     {
         // Do not look at cache in types derived from this type because they might incorrectly implement GetCustomAttributes
         return(ReflectedAttributeCache.GetMethodFilterAttributes(TaskMethodInfo));
     }
     return(base.GetFilterAttributes(useCache));
 }
 internal override IEnumerable <FilterAttribute> GetFilterAttributes(bool useCache)
 {
     if (useCache && GetType() == typeof(ReflectedAsyncControllerDescriptor))
     {
         // Do not look at cache in types derived from this type because they might incorrectly implement GetCustomAttributes
         return(ReflectedAttributeCache.GetTypeFilterAttributes(ControllerType));
     }
     return(base.GetFilterAttributes(useCache));
 }
예제 #4
0
        internal List <MethodInfo> GetMatchingAliasedMethods(ControllerContext controllerContext, string actionName)
        {
            // find all aliased methods which are opting in to this request
            // to opt in, all attributes defined on the method must return true

            var methods = from methodInfo in AliasedMethods
                          let attrs = ReflectedAttributeCache.GetActionNameSelectorAttributes(methodInfo)
                                      where attrs.All(attr => attr.IsValidName(controllerContext, actionName, methodInfo))
                                      select methodInfo;

            return(methods.ToList());
        }