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


C# Negotiator.WithModel方法代碼示例

本文整理匯總了C#中Nancy.Responses.Negotiation.Negotiator.WithModel方法的典型用法代碼示例。如果您正苦於以下問題:C# Negotiator.WithModel方法的具體用法?C# Negotiator.WithModel怎麽用?C# Negotiator.WithModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Nancy.Responses.Negotiation.Negotiator的用法示例。


在下文中一共展示了Negotiator.WithModel方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Handle

        public void Handle(HttpStatusCode statusCode, NancyContext context)
        {
            var response = new Negotiator(context);

            Error error = null;
            if (context.Items.ContainsKey("OnErrorException"))
            {
                var exception = context.Items["OnErrorException"] as Exception;
                error = new Error { ErrorMessage = exception.Message, FullException = exception.ToString() };
            }

            response.WithModel(new ErrorPageViewModel
                {
                    Title = "Sorry, something went wrong",
                    Summary = error == null ? "An unexpected error occurred." : error.ErrorMessage,
                    Details = error == null ? null : error.FullException // TODO: Obey "ShowFullErrors" flag in config
                }).WithStatusCode(statusCode).WithView("Error");

            var errorresponse = responseNegotiator.NegotiateResponse(response, context);
            string s = "";
            context.Response = errorresponse;
        }
開發者ID:jchannon,項目名稱:NowinReproIssue,代碼行數:22,代碼來源:ErrorStatusCodeHandler.cs

示例2: GetNegotiator

        private static Negotiator GetNegotiator(object routeResult, NancyContext context)
        {
            var negotiator = routeResult as Negotiator;

            if (negotiator == null)
            {
                context.WriteTraceLog(sb => sb.AppendFormat("[DefaultRouteInvoker] Wrapping result of type {0} in negotiator\n", routeResult.GetType()));

                negotiator = new Negotiator(context);
                negotiator.WithModel(routeResult);
            }

            return negotiator;
        }
開發者ID:JelleHissink,項目名稱:Nancy,代碼行數:14,代碼來源:DefaultRouteInvoker.cs


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