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


C# ODataProperty.SetSerializationInfo方法代码示例

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


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

示例1: ShouldBeAbleToSetThePropertySerializationInfo

 public void ShouldBeAbleToSetThePropertySerializationInfo()
 {
     ODataProperty property = new ODataProperty();
     ODataPropertySerializationInfo serializationInfo = new ODataPropertySerializationInfo();
     property.SetSerializationInfo(serializationInfo);
     property.SerializationInfo.Should().BeSameAs(serializationInfo);
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:7,代码来源:ODataObjectModelExtensionTests.cs

示例2: ShouldBeAbleToClearThePropertySerializationInfo

 public void ShouldBeAbleToClearThePropertySerializationInfo()
 {
     ODataProperty property = new ODataProperty();
     ODataPropertySerializationInfo serializationInfo = new ODataPropertySerializationInfo();
     property.SerializationInfo = serializationInfo;
     property.SetSerializationInfo(null);
     property.SerializationInfo.Should().BeNull();
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:ODataObjectModelExtensionTests.cs

示例3: CreateEmployeeEntryNoMetadata

        public static ODataEntry CreateEmployeeEntryNoMetadata(bool hasModel)
        {
            var employeeEntry = new ODataEntry()
            {
                TypeName = NameSpace + "Employee"
            };
            var employeeEntryP1 = new ODataProperty { Name = "PersonId", Value = -3 };
            var employeeEntryP2 = new ODataProperty
            {
                Name = "Name",
                Value = "ybqmssrdtjßcbhhmfxvhoxlssekuuibnmltiahdssxnpktmtorxfmeßbbujc"
            };
            var employeeEntryP3 = new ODataProperty { Name = "ManagersPersonId", Value = -465010984 };
            var employeeEntryP4 = new ODataProperty { Name = "Salary", Value = 0 };
            var employeeEntryP5 = new ODataProperty
            {
                Name = "Title",
                Value = "ミソまグたя縷ヲ弌ダゼ亜ゼをんゾ裹亜マゾダんタァハそポ縷ぁボグ黑珱ぁяポグソひゾひЯグポグボ欲を亜"
            };

            employeeEntry.Properties = new[] { employeeEntryP1, employeeEntryP2, employeeEntryP3, employeeEntryP4, employeeEntryP5 };
            if (!hasModel)
            {
                employeeEntryP1.SetSerializationInfo(new ODataPropertySerializationInfo()
                {
                    PropertyKind = ODataPropertyKind.Key
                });
            }

            return employeeEntry;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:31,代码来源:WritePayloadHelper.cs

示例4: CreatePersonEntryNoMetadata

        public static ODataEntry CreatePersonEntryNoMetadata(bool hasModel)
        {
            var personEntry = new ODataEntry()
            {
                TypeName = NameSpace + "Person"
            };

            var personEntryP1 = new ODataProperty { Name = "PersonId", Value = -5 };
            var personEntryP2 = new ODataProperty
            {
                Name = "Name",
                Value = "xhsdckkeqzvlnprheujeycqrglfehtdocildrequohlffazfgtvmddyqsaxrojqxrsckohrakdxlrghgmzqnyruzu"
            };

            personEntry.Properties = new[] { personEntryP1, personEntryP2 };
            if (!hasModel)
            {
                personEntryP1.SetSerializationInfo(new ODataPropertySerializationInfo()
                {
                    PropertyKind = ODataPropertyKind.Key
                });
            }

            return personEntry;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:25,代码来源:WritePayloadHelper.cs

示例5: CreateCustomerEntryNoMetadata

        public static ODataEntry CreateCustomerEntryNoMetadata(bool hasModel)
        {
            var customerEntry = new ODataEntry()
            {
                TypeName = NameSpace + "Customer"
            };

            var customerEntryP1 = new ODataProperty { Name = "CustomerId", Value = -9 };
            var customerEntryP2 = new ODataProperty { Name = "Name", Value = "CustomerName" };
            var customerEntryP3 = new ODataProperty
            {
                Name = "PrimaryContactInfo",
                Value = CreatePrimaryContactODataComplexValue()
            };
            var customerEntryP4 = new ODataProperty
            {
                Name = "BackupContactInfo",
                Value = CreateBackupContactODataCollectionValue()
            };
            var customerEntryP5 = new ODataProperty
            {
                Name = "Auditing",
                Value = CreateAuditInforODataComplexValue()
            };

            customerEntry.Properties = new[]
                {
                    customerEntryP1, customerEntryP2, customerEntryP3, customerEntryP4, customerEntryP5,
                };

            if (!hasModel)
            {
                customerEntry.SetSerializationInfo(new ODataFeedAndEntrySerializationInfo() { NavigationSourceName = "Customer", NavigationSourceEntityTypeName = NameSpace + "Customer" });
                customerEntryP1.SetSerializationInfo(new ODataPropertySerializationInfo()
                {
                    PropertyKind = ODataPropertyKind.Key
                });
            }

            return customerEntry;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:41,代码来源:WritePayloadHelper.cs

示例6: CreateOrderEntry2NoMetadata

        public static ODataEntry CreateOrderEntry2NoMetadata(bool hasModel)
        {
            var orderEntry2 = new ODataEntry()
            {
                TypeName = NameSpace + "Order"
            };

            var orderEntry2P1 = new ODataProperty { Name = "OrderId", Value = -9 };
            var orderEntry2P2 = new ODataProperty { Name = "CustomerId", Value = 78 };
            var orderEntry2P3 = new ODataProperty
            {
                Name = "Concurrency",
                Value = new ODataComplexValue()
                {
                    TypeName = NameSpace + "ConcurrencyInfo",
                    Properties = new[]
                                {
                                    new ODataProperty
                                        {
                                            Name = "Token",
                                            Value = "muunxfmcubaihvgnzoojgecdztyipapnxahnuibukrveamumfuokuvbly"
                                        },
                                    new ODataProperty
                                        {
                                            Name = "QueriedDateTime",
                                            Value = new DateTimeOffset(new DateTime(634646431705072026, System.DateTimeKind.Utc))
                                        }
                                }
                }
            };
            orderEntry2.Properties = new[] { orderEntry2P1, orderEntry2P2, orderEntry2P3 };
            if (!hasModel)
            {
                orderEntry2P1.SetSerializationInfo(new ODataPropertySerializationInfo()
                {
                    PropertyKind = ODataPropertyKind.Key
                });
            }

            return orderEntry2;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:41,代码来源:WritePayloadHelper.cs

示例7: SerializeEntryInFullMetadataJson

        private string SerializeEntryInFullMetadataJson(
            bool? useKeyAsSegment, 
            IEdmModel edmModel, 
            IEdmEntityType entityType = null, 
            IEdmEntitySet entitySet = null)
        {
            var settings = new ODataMessageWriterSettings
            {
                AutoComputePayloadMetadataInJson = true,
                UseKeyAsSegment = useKeyAsSegment,
            };

            settings.SetServiceDocumentUri(new Uri("http://example.com/"));

            var outputStream = new MemoryStream();
            var responseMessage = new InMemoryMessage {Stream = outputStream};
            responseMessage.SetHeader("Content-Type", "application/json;odata.metadata=full");
            string output;

            using(var messageWriter = new ODataMessageWriter((IODataResponseMessage)responseMessage, settings, edmModel))
            {
                var entryWriter = messageWriter.CreateODataEntryWriter(entitySet, entityType);
                ODataProperty keyProperty = new ODataProperty() {Name = "Key", Value = "KeyValue"};

                var entry = new ODataEntry {Properties = new[] {keyProperty}, TypeName = "Namespace.Person"};

                if (edmModel == null)
                {
                    keyProperty.SetSerializationInfo(new ODataPropertySerializationInfo
                    {
                        PropertyKind = ODataPropertyKind.Key
                    });

                    entry.SetSerializationInfo(new ODataFeedAndEntrySerializationInfo
                    {
                        NavigationSourceEntityTypeName = "Namespace.Person",
                        NavigationSourceName = "People",
                        ExpectedTypeName = "Namespace.Person"
                    });
                }

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

                outputStream.Seek(0, SeekOrigin.Begin);
                output = new StreamReader(outputStream).ReadToEnd();
            }

            return output;
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:51,代码来源:AutoGeneratedUrlsShouldPutKeyValueInDedicatedSegmentTests.cs

示例8: ShouldBeAbleToWriteFeedAndEntryResponseInJsonLightWithoutModel

        public void ShouldBeAbleToWriteFeedAndEntryResponseInJsonLightWithoutModel()
        {
            const string expectedPayload =
                "{" +
                    "\"@odata.context\":\"http://www.example.com/$metadata#Customers/NS.VIPCustomer\"," +
                    "\"value\":[" +
                        "{" +
                            "\"Name\":\"Bob\"," +
                            "\"[email protected]\":\"MostRecentOrder\"," +
                            "\"MostRecentOrder\":{\"OrderId\":101}" +
                        "}" +
                    "]" +
                "}";

            var writerSettings = new ODataMessageWriterSettings { DisableMessageStreamDisposal = true };
            writerSettings.SetContentType(ODataFormat.Json);
            writerSettings.ODataUri = new ODataUri() { ServiceRoot = new Uri("http://www.example.com") };

            MemoryStream stream = new MemoryStream();
            IODataResponseMessage responseMessage = new InMemoryMessage { StatusCode = 200, Stream = stream };

            // Write payload
            using (var messageWriter = new ODataMessageWriter(responseMessage, writerSettings))
            {
                var odataWriter = messageWriter.CreateODataFeedWriter();

                // Create customers feed with serializtion info to write odata.metadata.
                var customersFeed = new ODataFeed();
                customersFeed.SetSerializationInfo(new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "Customers", NavigationSourceEntityTypeName = "NS.Customer", ExpectedTypeName = "NS.VIPCustomer" });

                // Write customers feed.
                odataWriter.WriteStart(customersFeed);

                // Write VIP customer
                {
                    // Create VIP customer, don't need to pass in serialization info since the writer knows the context from the feed scope.
                    var vipCustomer = new ODataEntry { TypeName = "NS.VIPCustomer" };

                    var customerKey = new ODataProperty { Name = "Name", Value = "Bob" };

                    // Provide serialization info at the property level to compute the edit link.
                    customerKey.SetSerializationInfo(new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.Key });
                    vipCustomer.Properties = new[] { customerKey };

                    // Write customer entry.
                    odataWriter.WriteStart(vipCustomer);

                    // Write expanded most recent order
                    {
                        // No API to set serialization info on ODataNavigationLink since what we are adding on ODataFeed and ODataEntry should be sufficient for the 5.5 release.
                        var navigationLink = new ODataNavigationLink { Name = "MostRecentOrder", IsCollection = false, Url = new Uri("MostRecentOrder", UriKind.Relative) };
                        odataWriter.WriteStart(navigationLink);

                        // Write the most recent customer.
                        {
                            var mostRecentOrder = new ODataEntry { TypeName = "NS.Order" };

                            // Add serialization info so we can computer links.
                            mostRecentOrder.SetSerializationInfo(new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "Orders", NavigationSourceEntityTypeName = "NS.Order", ExpectedTypeName = "NS.Order" });

                            var orderKey = new ODataProperty { Name = "OrderId", Value = 101 };

                            // Provide serialization info at the property level to compute the edit link.
                            orderKey.SetSerializationInfo(new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.Key });
                            mostRecentOrder.Properties = new[] { orderKey };

                            // Write order entry.
                            odataWriter.WriteStart(mostRecentOrder);
                            odataWriter.WriteEnd();
                        }

                        // End navigationLink.
                        odataWriter.WriteEnd();
                    }

                    // End customer entry.
                    odataWriter.WriteEnd();
                }

                // End customers feed.
                odataWriter.WriteEnd();
            }

            stream.Position = 0;
            string payload = (new StreamReader(stream)).ReadToEnd();
            payload.Should().Be(expectedPayload);
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:87,代码来源:WritingJsonLightWithoutModelAcceptanceTests.cs

示例9: ShouldWriteOpenComplexPropertyForResponseEntryPayloadWithoutUserModel

 public void ShouldWriteOpenComplexPropertyForResponseEntryPayloadWithoutUserModel()
 {
     var complexProperty = new ODataProperty { Name = "OpenComplexProperty", Value = new ODataComplexValue { TypeName = "NS.MyDerivedEntityType", Properties = new[] { new ODataProperty { Name = "ComplexProperty", Value = new ODataComplexValue() } } } };
     complexProperty.SetSerializationInfo(new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.Open });
     var entry = new ODataEntry { TypeName = "NS.MyDerivedEntityType", Properties = new[] { complexProperty } };
     const string expectedPayload = "{\"@odata.context\":\"http://odata.org/test/$metadata#MySet/$entity\",\"@odata.type\":\"#NS.MyDerivedEntityType\",\"OpenComplexProperty\":{\"@odata.type\":\"NS.MyComplexType\",\"ComplexProperty\":{}}}";
     this.WriteNestedItemsAndValidatePayload(entitySetFullName: "MySet", derivedEntityTypeFullName: null, nestedItemToWrite: new[] { entry }, expectedPayload: expectedPayload, writingResponse: true);
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:ODataJsonLightWriterShortSpanIntegrationTests.cs

示例10: ShouldWriteOpenPrimitivePropertyWithoutTypeNameForRequestEntryPayloadWithoutUserModel

 public void ShouldWriteOpenPrimitivePropertyWithoutTypeNameForRequestEntryPayloadWithoutUserModel()
 {
     var property = new ODataProperty { Name = "OpenStringProperty", Value = new ODataPrimitiveValue(String.Empty) };
     property.SetSerializationInfo(new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.Open });
     var entry = new ODataEntry { TypeName = "NS.MyDerivedEntityType", Properties = new[] { property } };
     const string expectedPayload = "{\"OpenStringProperty\":\"\"}";
     this.WriteNestedItemsAndValidatePayload(entitySetFullName: "MySet", derivedEntityTypeFullName: "NS.MyDerivedEntityType", nestedItemToWrite: new[] { entry }, expectedPayload: expectedPayload, writingResponse: false, setMetadataDocumentUri: false);
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:ODataJsonLightWriterShortSpanIntegrationTests.cs

示例11: ShouldWriteOpenPrimitivePropertyWithoutTypeNameForResponseEntryPayloadWithoutUserModel

 public void ShouldWriteOpenPrimitivePropertyWithoutTypeNameForResponseEntryPayloadWithoutUserModel()
 {
     var property = new ODataProperty { Name = "OpenStringProperty", Value = new ODataPrimitiveValue(String.Empty + "K\uFFFF") };
     property.SetSerializationInfo(new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.Open });
     var entry = new ODataEntry { TypeName = "NS.MyDerivedEntityType", Properties = new[] { property } };
     const string expectedPayload = "{\"@odata.context\":\"http://odata.org/test/$metadata#MySet/NS.MyDerivedEntityType/$entity\",\"OpenStringProperty\":\"K\\uffff\"}";
     this.WriteNestedItemsAndValidatePayload(entitySetFullName: "MySet", derivedEntityTypeFullName: "NS.MyDerivedEntityType", nestedItemToWrite: new[] { entry }, expectedPayload: expectedPayload, writingResponse: true);
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:ODataJsonLightWriterShortSpanIntegrationTests.cs

示例12: WritePrimitivePropertyWithByteWithoutUserModel

 public void WritePrimitivePropertyWithByteWithoutUserModel()
 {
     var property = new ODataProperty { Name = "ByteProperty", Value = new ODataPrimitiveValue(Byte.MaxValue) };
     property.SetSerializationInfo(new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.Open });
     var entry = new ODataEntry { TypeName = "NS.MyDerivedEntityType", Properties = new[] { property } };
     const string expectedPayload = "{\"@odata.context\":\"http://odata.org/test/$metadata#MySet/$entity\",\"@odata.type\":\"#NS.MyDerivedEntityType\",\"[email protected]\":\"#Byte\",\"ByteProperty\":255}";
     this.WriteNestedItemsAndValidatePayload(entitySetFullName: "MySet", derivedEntityTypeFullName: null, nestedItemToWrite: new[] { entry }, expectedPayload: expectedPayload, writingResponse: true);
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:ODataJsonLightWriterShortSpanIntegrationTests.cs

示例13: GetODataPropertyForOpenProperty

        /// <summary>
        /// Returns the instance of ODataProperty with the given name and property value.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="propertyValue">Value of the property.</param>
        /// <returns>An instance of ODataProperty for the given property.</returns>
        private ODataProperty GetODataPropertyForOpenProperty(string propertyName, object propertyValue)
        {
            Debug.Assert(!string.IsNullOrEmpty(propertyName), "!string.IsNullOrEmpty(propertyName)");

            ResourceType propertyResourceType;
            if (WebUtil.IsNullValue(propertyValue))
            {
                propertyResourceType = ResourceType.PrimitiveStringResourceType;
            }
            else
            {
                propertyResourceType = WebUtil.GetResourceType(this.Provider, propertyValue);

                // A null ResourceType indicates a blacklisted type (eg, IntPtr or DateTimeOffset). So fail on it.
                if (propertyResourceType == null)
                {
                    throw new DataServiceException(500, Microsoft.OData.Service.Strings.Syndication_InvalidOpenPropertyType(propertyName));
                }
            }

            ODataProperty odataProperty = new ODataProperty
            {
                Name = propertyName,
                Value = this.GetPropertyValue(propertyName, propertyResourceType, propertyValue, true /*openProperty*/)
            };

            odataProperty.SetSerializationInfo(new ODataPropertySerializationInfo { PropertyKind = ODataPropertyKind.Open });
            return odataProperty;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:35,代码来源:EntitySerializer.cs

示例14: GetODataPropertyForEntityProperty

        /// <summary>Gets ODataProperty for the given <paramref name="property"/>.</summary>
        /// <param name="entityToSerialize">Entity that is currently being serialized.</param>
        /// <param name="property">ResourceProperty instance in question.</param>
        /// <returns>A instance of ODataProperty for the given <paramref name="property"/>.</returns>
        private ODataProperty GetODataPropertyForEntityProperty(EntityToSerialize entityToSerialize, ResourceProperty property)
        {
            Debug.Assert(entityToSerialize != null, "entityToSerialize != null");
            Debug.Assert(property != null && entityToSerialize.ResourceType.Properties.Contains(property), "property != null && currentResourceType.Properties.Contains(property)");

            ODataValue odataPropertyValue;
            if (property.IsOfKind(ResourcePropertyKind.Stream))
            {
                odataPropertyValue = this.GetNamedStreamPropertyValue(entityToSerialize, property);
            }
            else
            {
                object propertyValue = WebUtil.GetPropertyValue(this.Provider, entityToSerialize.Entity, entityToSerialize.ResourceType, property, null);
                odataPropertyValue = this.GetPropertyValue(property.Name, property.ResourceType, propertyValue, false /*openProperty*/);
            }

            ODataProperty odataProperty = new ODataProperty()
            {
                Name = property.Name,
                Value = odataPropertyValue
            };

            ODataPropertyKind kind = property.IsOfKind(ResourcePropertyKind.Key) ? ODataPropertyKind.Key : property.IsOfKind(ResourcePropertyKind.ETag) ? ODataPropertyKind.ETag : ODataPropertyKind.Unspecified;
            if (kind != ODataPropertyKind.Unspecified)
            {
                odataProperty.SetSerializationInfo(new ODataPropertySerializationInfo { PropertyKind = kind });
            }

            return odataProperty;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:34,代码来源:EntitySerializer.cs

示例15: CreateSpecialEmployeeEntryNoMetadata

        public static ODataEntry CreateSpecialEmployeeEntryNoMetadata(bool hasModel)
        {
            var employeeEntry = new ODataEntry()
            {
                TypeName = NameSpace + "SpecialEmployee"
            };
            var employeeEntryP1 = new ODataProperty { Name = "PersonId", Value = -10 };
            var employeeEntryP2 = new ODataProperty { Name = "Name", Value = "a special employee" };
            var employeeEntryP3 = new ODataProperty { Name = "ManagersPersonId", Value = 47 };
            var employeeEntryP4 = new ODataProperty { Name = "Salary", Value = 4091 };
            var employeeEntryP5 = new ODataProperty { Name = "Title", Value = "a special title" };
            var employeeEntryP6 = new ODataProperty { Name = "CarsVIN", Value = -1911530027 };
            var employeeEntryP7 = new ODataProperty { Name = "Bonus", Value = -37730565 };
            var employeeEntryP8 = new ODataProperty { Name = "IsFullyVested", Value = false };
            employeeEntry.Properties = new[] { employeeEntryP1, employeeEntryP2, employeeEntryP3, employeeEntryP4, employeeEntryP5, employeeEntryP6, employeeEntryP7, employeeEntryP8 };
            if (!hasModel)
            {
                employeeEntryP1.SetSerializationInfo(new ODataPropertySerializationInfo()
                {
                    PropertyKind = ODataPropertyKind.Key
                });
            }

            return employeeEntry;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:25,代码来源:WritePayloadHelper.cs


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