Example #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);
        }