本文整理匯總了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;
}
}