本文整理汇总了C#中Nancy.NancyContext.GetSerializationContextProvider方法的典型用法代码示例。如果您正苦于以下问题:C# NancyContext.GetSerializationContextProvider方法的具体用法?C# NancyContext.GetSerializationContextProvider怎么用?C# NancyContext.GetSerializationContextProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nancy.NancyContext
的用法示例。
在下文中一共展示了NancyContext.GetSerializationContextProvider方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
/// <summary>
/// Process the response
/// </summary>
/// <param name="requestedMediaRange">Content type requested by the client</param>
/// <param name="model">The model for the given media range</param>
/// <param name="context">The nancy context</param>
/// <returns>A response</returns>
public virtual Response Process(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
var pomonaResponse = (PomonaResponse)model;
string jsonString;
if (pomonaResponse.Entity == PomonaResponse.NoBodyEntity)
return new Response { StatusCode = pomonaResponse.StatusCode };
jsonString =
GetSerializerFactory(context,
context.GetSerializationContextProvider())
.GetSerializer().SerializeToString(pomonaResponse.Entity,
new SerializeOptions()
{
ExpandedPaths = pomonaResponse.ExpandedPaths,
ExpectedBaseType = pomonaResponse.ResultType
});
if (IsTextHtmlContentType(requestedMediaRange))
{
// Wrap in html
var response = new Response();
HtmlJsonPrettifier.CreatePrettifiedHtmlJsonResponse(response,
string.Empty,
jsonString,
"http://failfailtodo");
return response;
}
else
{
var bytes = Encoding.UTF8.GetBytes(jsonString);
var response = new Response
{
//Headers = {{"Content-Length", bytes.Length.ToString()}},
Contents = s => s.Write(bytes, 0, bytes.Length),
ContentType = ContentType,
StatusCode = pomonaResponse.StatusCode
};
if (pomonaResponse.ResponseHeaders != null)
{
foreach (var kvp in pomonaResponse.ResponseHeaders)
response.Headers.Add(kvp);
}
// Add etag header
var transformedResultType = pomonaResponse.ResultType as TransformedType;
if (transformedResultType != null)
{
var etagProperty = transformedResultType.ETagProperty;
if (pomonaResponse.Entity != null && etagProperty != null)
{
var etagValue = (string)etagProperty.Getter(pomonaResponse.Entity);
if (etagValue != null)
{
// I think defining this as a weak etag will be correct, since we can specify $expand which change data (byte-by-byte).
response.Headers["ETag"] = string.Format("W/\"{0}\"", etagValue);
}
}
}
return response;
}
}