本文整理汇总了C#中System.Web.Http.OData.Formatter.Serialization.ODataSerializerProvider.GetODataPayloadSerializer方法的典型用法代码示例。如果您正苦于以下问题:C# ODataSerializerProvider.GetODataPayloadSerializer方法的具体用法?C# ODataSerializerProvider.GetODataPayloadSerializer怎么用?C# ODataSerializerProvider.GetODataPayloadSerializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.OData.Formatter.Serialization.ODataSerializerProvider
的用法示例。
在下文中一共展示了ODataSerializerProvider.GetODataPayloadSerializer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSerializer
private ODataSerializer GetSerializer(Type type, object value, IEdmModel model, ODataSerializerProvider serializerProvider)
{
ODataSerializer serializer;
IEdmObject edmObject = value as IEdmObject;
if (edmObject != null)
{
IEdmTypeReference edmType = edmObject.GetEdmType();
if (edmType == null)
{
throw new SerializationException(
Error.Format(SRResources.EdmTypeCannotBeNull, type.FullName, typeof(IEdmObject).Name));
}
serializer = serializerProvider.GetEdmTypeSerializer(edmType);
if (serializer == null)
{
string message = Error.Format(SRResources.TypeCannotBeSerialized, edmType.ToTraceString(), typeof(ODataMediaTypeFormatter).Name);
throw new SerializationException(message);
}
}
else
{
// get the most appropriate serializer given that we support inheritance.
type = value == null ? type : value.GetType();
serializer = serializerProvider.GetODataPayloadSerializer(model, type, Request);
if (serializer == null)
{
string message = Error.Format(SRResources.TypeCannotBeSerialized, type.Name, typeof(ODataMediaTypeFormatter).Name);
throw new SerializationException(message);
}
}
return serializer;
}