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


C# EdmModel.SetPrimitiveValueConverter方法代码示例

本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmModel.SetPrimitiveValueConverter方法的典型用法代码示例。如果您正苦于以下问题:C# EdmModel.SetPrimitiveValueConverter方法的具体用法?C# EdmModel.SetPrimitiveValueConverter怎么用?C# EdmModel.SetPrimitiveValueConverter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.OData.Edm.Library.EdmModel的用法示例。


在下文中一共展示了EdmModel.SetPrimitiveValueConverter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UnsignedIntAndTypeDefinitionRoundtripJsonLightIntegrationTest

        public void UnsignedIntAndTypeDefinitionRoundtripJsonLightIntegrationTest()
        {
            var model = new EdmModel();

            var uint16 = new EdmTypeDefinition("MyNS", "UInt16", EdmPrimitiveTypeKind.Double);
            var uint16Ref = new EdmTypeDefinitionReference(uint16, false);
            model.AddElement(uint16);
            model.SetPrimitiveValueConverter(uint16Ref, UInt16ValueConverter.Instance);

            var uint64 = new EdmTypeDefinition("MyNS", "UInt64", EdmPrimitiveTypeKind.String);
            var uint64Ref = new EdmTypeDefinitionReference(uint64, false);
            model.AddElement(uint64);
            model.SetPrimitiveValueConverter(uint64Ref, UInt64ValueConverter.Instance);

            var guidType = new EdmTypeDefinition("MyNS", "Guid", EdmPrimitiveTypeKind.Int64);
            var guidRef = new EdmTypeDefinitionReference(guidType, true);
            model.AddElement(guidType);

            var personType = new EdmEntityType("MyNS", "Person");
            personType.AddKeys(personType.AddStructuralProperty("ID", uint64Ref));
            personType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            personType.AddStructuralProperty("FavoriteNumber", uint16Ref);
            personType.AddStructuralProperty("Age", model.GetUInt32("MyNS", true));
            personType.AddStructuralProperty("Guid", guidRef);
            personType.AddStructuralProperty("Weight", EdmPrimitiveTypeKind.Double);
            personType.AddStructuralProperty("Money", EdmPrimitiveTypeKind.Decimal);
            model.AddElement(personType);

            var container = new EdmEntityContainer("MyNS", "Container");
            var peopleSet = container.AddEntitySet("People", personType);
            model.AddElement(container);

            var stream = new MemoryStream();
            IODataResponseMessage message = new InMemoryMessage { Stream = stream };
            message.StatusCode = 200;

            var writerSettings = new ODataMessageWriterSettings();
            writerSettings.SetServiceDocumentUri(new Uri("http://host/service"));

            var messageWriter = new ODataMessageWriter(message, writerSettings, model);
            var entryWriter = messageWriter.CreateODataEntryWriter(peopleSet);

            var entry = new ODataEntry
            {
                TypeName = "MyNS.Person",
                Properties = new[]
                {
                    new ODataProperty
                    {
                        Name = "ID",
                        Value = UInt64.MaxValue
                    },
                    new ODataProperty
                    {
                        Name = "Name",
                        Value = "Foo"
                    },
                    new ODataProperty
                    {
                        Name = "FavoriteNumber",
                        Value = (UInt16)250
                    },
                    new ODataProperty
                    {
                        Name = "Age",
                        Value = (UInt32)123
                    },
                    new ODataProperty
                    {
                        Name = "Guid",
                        Value = Int64.MinValue
                    },
                    new ODataProperty
                    {
                        Name = "Weight",
                        Value = 123.45
                    },
                    new ODataProperty
                    {
                        Name = "Money",
                        Value = Decimal.MaxValue
                    }
                }
            };

            entryWriter.WriteStart(entry);
            entryWriter.WriteEnd();
            entryWriter.Flush();

            stream.Position = 0;

            StreamReader reader = new StreamReader(stream);
            string payload = reader.ReadToEnd();
            payload.Should().Be("{\"@odata.context\":\"http://host/service/$metadata#People/$entity\",\"ID\":\"18446744073709551615\",\"Name\":\"Foo\",\"FavoriteNumber\":250.0,\"Age\":123,\"Guid\":-9223372036854775808,\"Weight\":123.45,\"Money\":79228162514264337593543950335}");

            stream = new MemoryStream(Encoding.Default.GetBytes(payload));
            message = new InMemoryMessage { Stream = stream };
            message.StatusCode = 200;

            var readerSettings = new ODataMessageReaderSettings();
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:PrimitiveValuesRoundtripJsonLightTests.cs

示例2: WriteTypeDefinitionAsKeyPayloadShouldWork

        public void WriteTypeDefinitionAsKeyPayloadShouldWork()
        {
            EdmModel model = new EdmModel();

            EdmTypeDefinition uint32Type = new EdmTypeDefinition("NS", "UInt32", EdmPrimitiveTypeKind.String);
            EdmTypeDefinitionReference uint32Reference = new EdmTypeDefinitionReference(uint32Type, false);
            model.AddElement(uint32Type);

            EdmEntityType entityType = new EdmEntityType("NS", "Person");
            entityType.AddKeys(entityType.AddStructuralProperty("Id1", uint32Reference), entityType.AddStructuralProperty("Id2", EdmPrimitiveTypeKind.Int32));
            model.SetPrimitiveValueConverter(uint32Reference, new MyUInt32Converter());

            EdmTypeDefinition weightType = new EdmTypeDefinition("NS", "Weight", EdmPrimitiveTypeKind.Double);
            EdmTypeDefinitionReference weightTypeRef = new EdmTypeDefinitionReference(weightType, false);
            entityType.AddStructuralProperty("Weight", weightTypeRef);

            EdmComplexType complexType = new EdmComplexType("NS", "Address");
            EdmComplexTypeReference complexTypeRef = new EdmComplexTypeReference(complexType, true);

            EdmTypeDefinition addressType = new EdmTypeDefinition("NS", "Address", EdmPrimitiveTypeKind.String);
            EdmTypeDefinitionReference addressTypeRef = new EdmTypeDefinitionReference(addressType, false);
            complexType.AddStructuralProperty("CountryRegion", addressTypeRef);

            entityType.AddStructuralProperty("Address", complexTypeRef);

            model.AddElement(weightType);
            model.AddElement(addressType);
            model.AddElement(complexType);
            model.AddElement(entityType);

            EdmEntityContainer container = new EdmEntityContainer("EntityNs", "MyContainer");
            EdmEntitySet entitySet = container.AddEntitySet("People", entityType);
            model.AddElement(container);

            ODataEntry entry = new ODataEntry()
            {
                TypeName = "NS.Person",
                Properties = new[]
                {
                    new ODataProperty { Name = "Id1", Value = (UInt32)1 },
                    new ODataProperty { Name = "Id2", Value = 2 },
                    new ODataProperty { Name = "Weight", Value = 60.5 },
                    new ODataProperty
                    {
                        Name = "Address",
                        Value = new ODataComplexValue
                        {
                            Properties = new[]
                            {
                                new ODataProperty { Name = "CountryRegion", Value = "China" }
                            }
                        }
                    }
                }
            };

            string outputPayload = this.WriterEntry(model, entry, entitySet, entityType);

            const string expectedMinimalPayload =
                "{" +
                "\"@odata.context\":\"http://www.example.com/$metadata#People/$entity\"," +
                "\"Id1\":\"1\"," +
                "\"Id2\":2," +
                "\"Weight\":60.5," +
                "\"Address\":{\"CountryRegion\":\"China\"}" +
                "}";

            outputPayload.Should().Be(expectedMinimalPayload);

            outputPayload = this.WriterEntry(model, entry, entitySet, entityType, true);

            const string expectedFullPayload =
                "{" +
                "\"@odata.context\":\"http://www.example.com/$metadata#People/$entity\"," +
                "\"@odata.type\":\"#NS.Person\"," +
                "\"@odata.id\":\"People(Id1='1',Id2=2)\"," +
                "\"@odata.editLink\":\"People(Id1='1',Id2=2)\"," +
                "\"Id1\":\"1\"," +
                "\"Id2\":2," +
                "\"Weight\":60.5," +
                "\"Address\":{\"CountryRegion\":\"China\"}" +
                "}";

            outputPayload.Should().Be(expectedFullPayload);
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:85,代码来源:PropertyAndValueJsonLightWriterIntegrationTests.cs

示例3: PassNullConverterToSetPrimitiveValueConverterShouldFail

 public void PassNullConverterToSetPrimitiveValueConverterShouldFail()
 {
     var model = new EdmModel();
     var typeReference = new EdmTypeDefinitionReference(new EdmTypeDefinition("NS", "Test", EdmPrimitiveTypeKind.Int32), true);
     Action setConverter = () => model.SetPrimitiveValueConverter(typeReference, null);
     setConverter.ShouldThrow<ArgumentNullException>();
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:7,代码来源:ExtensionMethodsTests.cs

示例4: PassNullTypeReferenceToSetPrimitiveValueConverterShouldFail

 public void PassNullTypeReferenceToSetPrimitiveValueConverterShouldFail()
 {
     var model = new EdmModel();
     var converter = new TestPrimitiveValueConverter();
     Action setConverter = () => model.SetPrimitiveValueConverter((IEdmTypeDefinitionReference)null, converter);
     setConverter.ShouldThrow<ArgumentNullException>();
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:7,代码来源:ExtensionMethodsTests.cs

示例5: SetAndGetPrimitiveValueConverterShouldWork

 public void SetAndGetPrimitiveValueConverterShouldWork()
 {
     var model = new EdmModel();
     var typeReference = new EdmTypeDefinitionReference(new EdmTypeDefinition("NS", "Test", EdmPrimitiveTypeKind.Int32), true);
     var converter = new TestPrimitiveValueConverter();
     model.SetPrimitiveValueConverter(typeReference, converter);
     Assert.AreEqual(model.GetPrimitiveValueConverter(typeReference), converter);
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:8,代码来源:ExtensionMethodsTests.cs


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