當前位置: 首頁>>代碼示例>>C#>>正文


C# HttpRequestMessage.SetODataPathHandler方法代碼示例

本文整理匯總了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());
        }
開發者ID:naulizzang,項目名稱:aspnetwebstack,代碼行數:11,代碼來源:ODataHttpRequestMessageExtensionsTest.cs

示例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;
        }
開發者ID:jordansjones,項目名稱:ODataVersioning,代碼行數:49,代碼來源:VersionAwareODataPathRouteConstraint.cs

示例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;
            }
        }
開發者ID:quentez,項目名稱:aspnetwebstack,代碼行數:65,代碼來源:ODataPathRouteConstraint.cs


注:本文中的System.Net.Http.HttpRequestMessage.SetODataPathHandler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。