本文整理汇总了C#中System.Net.Http.HttpRequestMessage.SetODataPathHandler方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestMessage.SetODataPathHandler方法的具体用法?C# HttpRequestMessage.SetODataPathHandler怎么用?C# HttpRequestMessage.SetODataPathHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpRequestMessage
的用法示例。
在下文中一共展示了HttpRequestMessage.SetODataPathHandler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetODataPathHandlerThenGetReturnsWhatYouSet
public void SetODataPathHandlerThenGetReturnsWhatYouSet()
{
HttpRequestMessage request = new HttpRequestMessage();
IODataPathHandler parser = new Mock<IODataPathHandler>().Object;
// Act
request.SetODataPathHandler(parser);
// Assert
Assert.Same(parser, request.GetODataPathHandler());
}
示例2: Match
public override bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (routeDirection != HttpRouteDirection.UriResolution)
{
return true;
}
object odataPathValue;
if (!values.TryGetValue(ODataRouteConstants.ODataPath, out odataPathValue))
{
return false;
}
var pathString = odataPathValue as string;
if (pathString == null) pathString = string.Empty;
ODataPath path = null;
try
{
path = VersionAwarePathHandler.Parse(request, EdmModel, pathString);
}
catch (ODataException e)
{
throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid OData path", e));
}
if (path != null)
{
values[ODataRouteConstants.ODataPath] = path.Segments.First();
// Set all the properties we need for routing, querying, formatting
request.SetEdmModel(EdmModel);
request.SetODataPathHandler(VersionAwarePathHandler);
request.SetODataPath(path);
request.SetODataRouteName(RouteName);
request.SetODataRoutingConventions(RoutingConventions);
if (!values.ContainsKey(ODataRouteConstants.Controller))
{
// Select controller name using the routing conventions
string controllerName = SelectControllerName(path, request);
if (controllerName != null)
{
values[ODataRouteConstants.Controller] = controllerName;
}
}
}
return path != null;
}
示例3: Match
public virtual bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (request == null)
{
throw Error.ArgumentNull("request");
}
if (values == null)
{
throw Error.ArgumentNull("values");
}
if (routeDirection == HttpRouteDirection.UriResolution)
{
object odataPathRouteValue;
if (values.TryGetValue(ODataRouteConstants.ODataPath, out odataPathRouteValue))
{
string odataPath = odataPathRouteValue as string;
if (odataPath == null)
{
// No odataPath means the path is empty; this is necessary for service documents
odataPath = String.Empty;
}
ODataPath path;
try
{
path = PathHandler.Parse(EdmModel, odataPath);
}
catch (ODataException e)
{
throw new HttpResponseException(
request.CreateErrorResponse(HttpStatusCode.NotFound, SRResources.ODataPathInvalid, e));
}
if (path != null)
{
// Set all the properties we need for routing, querying, formatting
request.SetEdmModel(EdmModel);
request.SetODataPathHandler(PathHandler);
request.SetODataPath(path);
request.SetODataRouteName(RouteName);
request.SetODataRoutingConventions(RoutingConventions);
if (!values.ContainsKey(ODataRouteConstants.Controller))
{
// Select controller name using the routing conventions
string controllerName = SelectControllerName(path, request);
if (controllerName != null)
{
values[ODataRouteConstants.Controller] = controllerName;
}
}
return true;
}
}
return false;
}
else
{
// This constraint only applies to URI resolution
return true;
}
}