예제 #1
0
            // This method lazy-initializes the data needed for action selection. This is a safe race-condition. This is
            // done because we don't know whether or not an action/controller is attribute routed until after attribute
            // routes are added.
            private void InitializeStandardActions()
            {
                if (_standardActions != null)
                {
                    return;
                }

                StandardActionSelectionCache standardActions = new StandardActionSelectionCache();

                if (_controllerDescriptor.IsAttributeRouted())
                {
                    // The controller has an attribute route; no actionsByVerb are accessible via standard routing.
                    standardActions.StandardCandidateActions = new CandidateAction[0];
                }
                else
                {
                    // The controller does not have an attribute route; some actionsByVerb may be accessible via standard
                    // routing.
                    List <CandidateAction> standardCandidateActions = new List <CandidateAction>();

                    for (int i = 0; i < _combinedCandidateActions.Length; i++)
                    {
                        CandidateAction candidate = _combinedCandidateActions[i];

                        // We know that this cast is safe before we created all of the action descriptors for standard actions
                        ReflectedHttpActionDescriptor action = (ReflectedHttpActionDescriptor)candidate.ActionDescriptor;

                        // Allow standard routes access inherited actionsByVerb or actionsByVerb without Route attributes.
                        if (action.MethodInfo.DeclaringType != _controllerDescriptor.ControllerType ||
                            !candidate.ActionDescriptor.IsAttributeRouted())
                        {
                            standardCandidateActions.Add(candidate);
                        }
                    }

                    standardActions.StandardCandidateActions = standardCandidateActions.ToArray();
                }

                standardActions.StandardActionNameMapping =
                    standardActions.StandardCandidateActions
                    .Select(c => c.ActionDescriptor)
                    .ToLookup(actionDesc => actionDesc.ActionName, StringComparer.OrdinalIgnoreCase);

                // Bucket the action descriptors by common verbs.
                int len = _cacheListVerbKinds.Length;

                standardActions.CacheListVerbs = new CandidateAction[len][];
                for (int i = 0; i < len; i++)
                {
                    standardActions.CacheListVerbs[i] = FindActionsForVerbWorker(_cacheListVerbKinds[i], standardActions.StandardCandidateActions);
                }

                _standardActions = standardActions;
            }
            void InitializeStandardActions()
            {
                if (standardActions != null)
                {
                    return;
                }

                var selectionCache = new StandardActionSelectionCache();

                if (controllerDescriptor.IsAttributeRouted())
                {
                    selectionCache.StandardCandidateActions = new CandidateAction[0];
                }
                else
                {
                    var standardCandidateActions = new List <CandidateAction>();

                    for (var i = 0; i < combinedCandidateActions.Length; i++)
                    {
                        var candidate = combinedCandidateActions[i];
                        var action    = (ReflectedHttpActionDescriptor)candidate.ActionDescriptor;

                        if (action.MethodInfo.DeclaringType != controllerDescriptor.ControllerType || !candidate.ActionDescriptor.IsAttributeRouted())
                        {
                            standardCandidateActions.Add(candidate);
                        }
                    }

                    selectionCache.StandardCandidateActions = standardCandidateActions.ToArray();
                }

                selectionCache.StandardActionNameMapping = selectionCache.StandardCandidateActions.Select(c => c.ActionDescriptor).ToLookup(actionDesc => actionDesc.ActionName, OrdinalIgnoreCase);

                var len = cacheListVerbKinds.Length;

                selectionCache.CacheListVerbs = new CandidateAction[len][];

                for (var i = 0; i < len; i++)
                {
                    selectionCache.CacheListVerbs[i] = FindActionsForVerbWorker(cacheListVerbKinds[i], selectionCache.StandardCandidateActions);
                }

                standardActions = selectionCache;
            }
            // This method lazy-initializes the data needed for action selection. This is a safe race-condition. This is
            // done because we don't know whether or not an action/controller is attribute routed until after attribute
            // routes are added.
            private void InitializeStandardActions()
            {
                if (_standardActions != null)
                {
                    return;
                }

                StandardActionSelectionCache standardActions = new StandardActionSelectionCache();

                if (_controllerDescriptor.IsAttributeRouted())
                {
                    // The controller has an attribute route; no actionsByVerb are accessible via standard routing.
                    standardActions.StandardCandidateActions = new CandidateAction[0];
                }
                else
                {
                    // The controller does not have an attribute route; some actionsByVerb may be accessible via standard
                    // routing.
                    List<CandidateAction> standardCandidateActions = new List<CandidateAction>();

                    for (int i = 0; i < _combinedCandidateActions.Length; i++)
                    {
                        CandidateAction candidate = _combinedCandidateActions[i];

                        // We know that this cast is safe before we created all of the action descriptors for standard actions
                        ReflectedHttpActionDescriptor action = (ReflectedHttpActionDescriptor)candidate.ActionDescriptor;

                        // Allow standard routes access inherited actionsByVerb or actionsByVerb without Route attributes.
                        if (action.MethodInfo.DeclaringType != _controllerDescriptor.ControllerType
                            || !candidate.ActionDescriptor.IsAttributeRouted())
                        {
                            standardCandidateActions.Add(candidate);
                        }
                    }

                    standardActions.StandardCandidateActions = standardCandidateActions.ToArray();
                }

                standardActions.StandardActionNameMapping =
                    standardActions.StandardCandidateActions
                    .Select(c => c.ActionDescriptor)
                    .ToLookup(actionDesc => actionDesc.ActionName, StringComparer.OrdinalIgnoreCase);

                // Bucket the action descriptors by common verbs.
                int len = _cacheListVerbKinds.Length;
                standardActions.CacheListVerbs = new CandidateAction[len][];
                for (int i = 0; i < len; i++)
                {
                    standardActions.CacheListVerbs[i] = FindActionsForVerbWorker(_cacheListVerbKinds[i], standardActions.StandardCandidateActions);
                }

                _standardActions = standardActions;
            }