本文整理汇总了C#中System.Web.Http.OData.Formatter.Serialization.ODataSerializerContext.GetEdmType方法的典型用法代码示例。如果您正苦于以下问题:C# ODataSerializerContext.GetEdmType方法的具体用法?C# ODataSerializerContext.GetEdmType怎么用?C# ODataSerializerContext.GetEdmType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.OData.Formatter.Serialization.ODataSerializerContext
的用法示例。
在下文中一共展示了ODataSerializerContext.GetEdmType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteObject
/// <inheritdoc />
public override void WriteObject(object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)
{
if (messageWriter == null)
{
throw Error.ArgumentNull("messageWriter");
}
if (writeContext == null)
{
throw Error.ArgumentNull("writeContext");
}
IEdmEntitySet entitySet = writeContext.EntitySet;
if (entitySet == null)
{
throw new SerializationException(SRResources.EntitySetMissingDuringSerialization);
}
IEdmTypeReference feedType = writeContext.GetEdmType(graph, type);
Contract.Assert(feedType != null);
IEdmEntityTypeReference entityType = GetEntityType(feedType);
ODataWriter writer = messageWriter.CreateODataFeedWriter(entitySet, entityType.EntityDefinition());
WriteObjectInline(graph, feedType, writer, writeContext);
}
示例2: WriteObject
/// <inheritdoc/>
public override void WriteObject(object graph, Type type, ODataMessageWriter messageWriter,
ODataSerializerContext writeContext)
{
if (messageWriter == null)
{
throw Error.ArgumentNull("messageWriter");
}
if (writeContext == null)
{
throw Error.ArgumentNull("writeContext");
}
IEdmTypeReference collectionType = writeContext.GetEdmType(graph, type);
Contract.Assert(collectionType != null);
IEdmTypeReference elementType = GetElementType(collectionType);
ODataCollectionWriter writer = messageWriter.CreateODataCollectionWriter(elementType);
WriteCollection(writer, graph, collectionType.AsCollection(), writeContext);
}
示例3: WriteObject
/// <inheritdoc/>
public override void WriteObject(object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)
{
if (messageWriter == null)
{
throw Error.ArgumentNull("messageWriter");
}
if (writeContext == null)
{
throw Error.ArgumentNull("writeContext");
}
if (writeContext.RootElementName == null)
{
throw Error.Argument("writeContext", SRResources.RootElementNameMissing, typeof(ODataSerializerContext).Name);
}
IEdmTypeReference edmType = writeContext.GetEdmType(graph, type);
Contract.Assert(edmType != null);
messageWriter.WriteProperty(CreateProperty(graph, edmType, writeContext.RootElementName, writeContext));
}
示例4: GetEdmType_ThrowsInvalidOperation_IfEdmObjectGetEdmTypeReturnsNull
public void GetEdmType_ThrowsInvalidOperation_IfEdmObjectGetEdmTypeReturnsNull()
{
// Arrange (this code path does not use ODataSerializerContext fields or properties)
var context = new ODataSerializerContext();
Mock<IEdmObject> mock = new Mock<IEdmObject>(MockBehavior.Strict);
mock.Setup(edmObject => edmObject.GetEdmType()).Returns<IEdmTypeReference>(null).Verifiable();
// Act & Assert
Assert.Throws<InvalidOperationException>(() => context.GetEdmType(mock.Object, null),
exceptionMessage: "The EDM type of the object of type 'Castle.Proxies.IEdmObjectProxy' is null. " +
"The EDM type of an IEdmObject cannot be null.");
mock.Verify();
}
示例5: GetEntityType
private IEdmEntityTypeReference GetEntityType(object graph, ODataSerializerContext writeContext)
{
Contract.Assert(graph != null);
IEdmTypeReference edmType = writeContext.GetEdmType(graph, graph.GetType());
Contract.Assert(edmType != null);
if (!edmType.IsEntity())
{
throw new SerializationException(
Error.Format(SRResources.CannotWriteType, GetType().Name, edmType.FullName()));
}
return edmType.AsEntity();
}