本文整理汇总了C#中System.Web.Http.Controllers.HttpControllerContext.AddFunctionParameterToRouteData方法的典型用法代码示例。如果您正苦于以下问题:C# HttpControllerContext.AddFunctionParameterToRouteData方法的具体用法?C# HttpControllerContext.AddFunctionParameterToRouteData怎么用?C# HttpControllerContext.AddFunctionParameterToRouteData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.Controllers.HttpControllerContext
的用法示例。
在下文中一共展示了HttpControllerContext.AddFunctionParameterToRouteData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectAction
/// <inheritdoc/>
public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext,
ILookup<string, HttpActionDescriptor> actionMap)
{
if (odataPath == null)
{
throw Error.ArgumentNull("odataPath");
}
if (controllerContext == null)
{
throw Error.ArgumentNull("controllerContext");
}
if (actionMap == null)
{
throw Error.ArgumentNull("actionMap");
}
if (controllerContext.Request.Method == HttpMethod.Get)
{
string actionName = null;
switch (odataPath.PathTemplate)
{
case "~/entityset/key/cast/function":
case "~/entityset/key/function":
actionName = GetFunction(odataPath).SelectAction(actionMap, isCollection: false);
if (actionName != null)
{
controllerContext.AddKeyValueToRouteData(odataPath);
}
break;
case "~/entityset/cast/function":
case "~/entityset/function":
actionName = GetFunction(odataPath).SelectAction(actionMap, isCollection: true);
break;
case "~/singleton/function":
case "~/singleton/cast/function":
actionName = GetFunction(odataPath).SelectAction(actionMap, isCollection: false);
break;
}
if (actionName != null)
{
controllerContext.AddFunctionParameterToRouteData(odataPath.Segments.Last() as BoundFunctionPathSegment);
return actionName;
}
}
return null;
}
示例2: SelectAction
/// <inheritdoc/>
public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext,
ILookup<string, HttpActionDescriptor> actionMap)
{
if (odataPath == null)
{
throw Error.ArgumentNull("odataPath");
}
if (controllerContext == null)
{
throw Error.ArgumentNull("controllerContext");
}
if (actionMap == null)
{
throw Error.ArgumentNull("actionMap");
}
if (controllerContext.Request.Method == HttpMethod.Get)
{
string actionName = null;
BoundFunctionPathSegment function = null;
switch (odataPath.PathTemplate)
{
case "~/entityset/key/cast/function":
case "~/entityset/key/function":
function = odataPath.Segments.Last() as BoundFunctionPathSegment;
actionName = GetFunction(function).SelectAction(actionMap, isCollection: false);
if (actionName != null)
{
EntitySetPathSegment entitySetPathSegment = (EntitySetPathSegment)odataPath.Segments.First();
IEdmEntityType edmEntityType = entitySetPathSegment.EntitySetBase.EntityType();
KeyValuePathSegment keyValueSegment = (KeyValuePathSegment)odataPath.Segments[1];
controllerContext.AddKeyValueToRouteData(keyValueSegment, edmEntityType, ODataRouteConstants.Key);
}
break;
case "~/entityset/key/cast/function/$count":
case "~/entityset/key/function/$count":
function = odataPath.Segments[odataPath.Segments.Count - 2] as BoundFunctionPathSegment;
actionName = GetFunction(function).SelectAction(actionMap, isCollection: false);
if (actionName != null)
{
EntitySetPathSegment entitySetPathSegment = (EntitySetPathSegment)odataPath.Segments.First();
IEdmEntityType edmEntityType = entitySetPathSegment.EntitySetBase.EntityType();
KeyValuePathSegment keyValueSegment = (KeyValuePathSegment)odataPath.Segments[1];
controllerContext.AddKeyValueToRouteData(keyValueSegment, edmEntityType, ODataRouteConstants.Key);
}
break;
case "~/entityset/cast/function":
case "~/entityset/function":
function = odataPath.Segments.Last() as BoundFunctionPathSegment;
actionName = GetFunction(function).SelectAction(actionMap, isCollection: true);
break;
case "~/entityset/cast/function/$count":
case "~/entityset/function/$count":
function = odataPath.Segments[odataPath.Segments.Count - 2] as BoundFunctionPathSegment;
actionName = GetFunction(function).SelectAction(actionMap, isCollection: true);
break;
case "~/singleton/function":
case "~/singleton/cast/function":
function = odataPath.Segments.Last() as BoundFunctionPathSegment;
actionName = GetFunction(function).SelectAction(actionMap, isCollection: false);
break;
case "~/singleton/function/$count":
case "~/singleton/cast/function/$count":
function = odataPath.Segments[odataPath.Segments.Count - 2] as BoundFunctionPathSegment;
actionName = GetFunction(function).SelectAction(actionMap, isCollection: false);
break;
}
if (actionName != null)
{
controllerContext.AddFunctionParameterToRouteData(function);
return actionName;
}
}
return null;
}