本文整理汇总了C#中HttpControllerDescriptor.HasRoutingAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# HttpControllerDescriptor.HasRoutingAttribute方法的具体用法?C# HttpControllerDescriptor.HasRoutingAttribute怎么用?C# HttpControllerDescriptor.HasRoutingAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpControllerDescriptor
的用法示例。
在下文中一共展示了HttpControllerDescriptor.HasRoutingAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ActionSelectorCacheItem
public ActionSelectorCacheItem(HttpControllerDescriptor controllerDescriptor)
{
Contract.Assert(controllerDescriptor != null);
// Initialize the cache entirely in the ctor on a single thread.
_controllerDescriptor = controllerDescriptor;
MethodInfo[] allMethods = _controllerDescriptor.ControllerType.GetMethods(BindingFlags.Instance | BindingFlags.Public);
MethodInfo[] validMethods = Array.FindAll(allMethods, IsValidActionMethod);
_combinedCandidateActions = new CandidateAction[validMethods.Length];
for (int i = 0; i < validMethods.Length; i++)
{
MethodInfo method = validMethods[i];
ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor(_controllerDescriptor, method);
_combinedCandidateActions[i] = new CandidateAction
{
ActionDescriptor = actionDescriptor
};
HttpActionBinding actionBinding = actionDescriptor.ActionBinding;
// Building an action parameter name mapping to compare against the URI parameters coming from the request. Here we only take into account required parameters that are simple types and come from URI.
_actionParameterNames.Add(
actionDescriptor,
actionBinding.ParameterBindings
.Where(binding => !binding.Descriptor.IsOptional && TypeHelper.CanConvertFromString(binding.Descriptor.ParameterType) && binding.WillReadUri())
.Select(binding => binding.Descriptor.Prefix ?? binding.Descriptor.ParameterName).ToArray());
}
if (controllerDescriptor.HasRoutingAttribute())
{
// The controller has an attribute route; no actions are accessible via standard routing.
_standardCandidateActions = new CandidateAction[0];
}
else
{
// The controller does not have an attribute route; some actions may be accessible via standard
// routing.
List<CandidateAction> standardCandidateActions = new List<CandidateAction>();
for (int i = 0; i < _combinedCandidateActions.Length; i++)
{
CandidateAction candidate = _combinedCandidateActions[i];
// Allow standard routes access inherited actions or actions without Route attributes.
if (((ReflectedHttpActionDescriptor)candidate.ActionDescriptor).MethodInfo.DeclaringType != controllerDescriptor.ControllerType
|| !candidate.ActionDescriptor.HasRoutingAttribute())
{
standardCandidateActions.Add(candidate);
}
}
_standardCandidateActions = standardCandidateActions.ToArray();
}
_combinedActionNameMapping = _combinedCandidateActions.Select(c => c.ActionDescriptor).ToLookup(actionDesc => actionDesc.ActionName, StringComparer.OrdinalIgnoreCase);
_standardActionNameMapping = _standardCandidateActions.Select(c => c.ActionDescriptor).ToLookup(actionDesc => actionDesc.ActionName, StringComparer.OrdinalIgnoreCase);
// Bucket the action descriptors by common verbs.
int len = _cacheListVerbKinds.Length;
_cacheListVerbs = new CandidateAction[len][];
for (int i = 0; i < len; i++)
{
_cacheListVerbs[i] = FindActionsForVerbWorker(_cacheListVerbKinds[i]);
}
}