当前位置: 首页>>代码示例>>C#>>正文


C# ODataSerializerContext.GetEdmType方法代码示例

本文整理汇总了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);
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:26,代码来源:ODataFeedSerializer.cs

示例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);
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:21,代码来源:ODataCollectionSerializer.cs

示例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));
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:21,代码来源:ODataPrimitiveSerializer.cs

示例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();
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:13,代码来源:ODataSerializerContextTest.cs

示例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();
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:15,代码来源:ODataEntityTypeSerializer.cs


注:本文中的System.Web.Http.OData.Formatter.Serialization.ODataSerializerContext.GetEdmType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。