• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Core.ODataProperty类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ODataProperty类属于Microsoft.OData.Core命名空间,在下文中一共展示了ODataProperty类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ApplyProperty

        internal static void ApplyProperty(ODataProperty property, IEdmStructuredTypeReference resourceType, object resource,
            ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext, AssembliesResolver assembliesResolver)
        {
            IEdmProperty edmProperty = resourceType.FindProperty(property.Name);

            bool isDynamicProperty = false;
            string propertyName = property.Name;
            if (edmProperty != null)
            {
                propertyName = EdmLibHelpers.GetClrPropertyName(edmProperty, readContext.Model);
            }
            else
            {
                IEdmStructuredType structuredType = resourceType.StructuredDefinition();
                isDynamicProperty = structuredType != null && structuredType.IsOpen;
            }

            // dynamic properties have null values
            IEdmTypeReference propertyType = edmProperty != null ? edmProperty.Type : null;

            EdmTypeKind propertyKind;
            object value = ConvertValue(property.Value, ref propertyType, deserializerProvider, readContext,
                out propertyKind);

            if (isDynamicProperty)
            {
                SetDynamicProperty(resource, resourceType, propertyKind, propertyName, value, propertyType,
                    readContext, assembliesResolver);
            }
            else
            {
                SetDeclaredProperty(resource, propertyKind, propertyName, value, edmProperty, readContext, assembliesResolver);
            }
        }
开发者ID:joshcomley,项目名称:WebApi,代码行数:34,代码来源:DeserializationHelpers.cs


示例2: ValidatePropertyNotNull

 /// <summary>
 /// Validates an <see cref="ODataProperty"/> for not being null.
 /// </summary>
 /// <param name="property">The property to validate for not being null.</param>
 internal static void ValidatePropertyNotNull(ODataProperty property)
 {
     if (property == null)
     {
         throw new ODataException(Strings.WriterValidationUtils_PropertyMustNotBeNull);
     }
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:11,代码来源:WriterValidationUtils.cs


示例3: ApplyProperty

        internal static void ApplyProperty(ODataProperty property, IEdmStructuredTypeReference resourceType, object resource,
            ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext)
        {
            IEdmProperty edmProperty = resourceType.FindProperty(property.Name);

            string propertyName = property.Name;
            if (edmProperty != null)
            {
                propertyName = EdmLibHelpers.GetClrPropertyName(edmProperty, readContext.Model);
            }
            IEdmTypeReference propertyType = edmProperty != null ? edmProperty.Type : null; // open properties have null values

            EdmTypeKind propertyKind;
            object value = ConvertValue(property.Value, ref propertyType, deserializerProvider, readContext, out propertyKind);

            if (propertyKind == EdmTypeKind.Collection)
            {
                SetCollectionProperty(resource, edmProperty, value, propertyName);
            }
            else
            {
                if (propertyKind == EdmTypeKind.Primitive && !readContext.IsUntyped)
                {
                    value = EdmPrimitiveHelpers.ConvertPrimitiveValue(value, GetPropertyType(resource, propertyName));
                }

                SetProperty(resource, propertyName, value);
            }
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:29,代码来源:DeserializationHelpers.cs


示例4: WriteProperty

 public override void WriteProperty(ODataProperty property)
 {
     var schema = this.AvroWriter.UpdateSchema(property.Value, null);
     var obj = ODataAvroConvert.FromODataObject(property.Value, schema);
     this.AvroWriter.Write(obj);
     this.Flush();
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:7,代码来源:ODataAvroOutputContext.cs


示例5: WriteProperty

        public override void WriteProperty(ODataProperty property)
        {
            var val = property.Value as ODataComplexValue;
            if (val == null)
            {
                throw new ApplicationException("only support write complex type property.");
            }

            this.writer.WriteStart();
            foreach (ODataProperty prop in val.Properties)
            {
                string name = null;
                string @params = string.Empty;

                int idx = prop.Name.IndexOf('_');
                if (idx < 0)
                {
                    name = prop.Name;
                }
                else
                {
                    name = prop.Name.Substring(0, idx);
                    @params = string.Join(";", prop.Name.Substring(idx + 1).Split('_'));
                }

                foreach (ODataInstanceAnnotation anns in prop.InstanceAnnotations)
                {
                    @params += ";" + anns.Name.Substring(6) /*VCARD.*/ + "=" + ((ODataPrimitiveValue)anns.Value).Value;
                }

                this.writer.WriteItem(null, name, @params, (string)prop.Value);
            }

            this.writer.WriteEnd();
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:35,代码来源:VCardOutputContext.cs


示例6: 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


示例7: 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


示例8: ApplyNonExistantPropertyWithIgnoreMissingPropertiesShouldNotError

        public void ApplyNonExistantPropertyWithIgnoreMissingPropertiesShouldNotError()
        {
            TestMaterializerContext context = new TestMaterializerContext() {IgnoreMissingProperties = true};
            CollectionValueMaterializationPolicyTests.Point point = new CollectionValueMaterializationPolicyTests.Point();
            ODataProperty property = new ODataProperty() {Name = "Z", Value = 10};

            this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(CollectionValueMaterializationPolicyTests.Point), null), property, point);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:8,代码来源:ComplexValueMaterializationPolicyTests.cs


示例9: CreateProperty

 private static ODataProperty CreateProperty(string name, object value)
 {
     ODataProperty prop = new ODataProperty()
     {
         Name = name,
         Value = value,
     };
     return prop;
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:9,代码来源:ODataPayloadElementPropertyWriter.cs


示例10: ReadPrimitive

        /// <summary>
        /// Deserializes the primitive from the given <paramref name="primitiveProperty"/> under the given <paramref name="readContext"/>.
        /// </summary>
        /// <param name="primitiveProperty">The primitive property to deserialize.</param>
        /// <param name="readContext">The deserializer context.</param>
        /// <returns>The deserialized OData primitive value.</returns>
        public virtual object ReadPrimitive(ODataProperty primitiveProperty, ODataDeserializerContext readContext)
        {
            if (primitiveProperty == null)
            {
                throw Error.ArgumentNull("primitiveProperty");
            }

            return primitiveProperty.Value;
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:15,代码来源:ODataPrimitiveDeserializer.cs


示例11: ApplyODataComplexValueForCollectionPropertyShouldError

        public void ApplyODataComplexValueForCollectionPropertyShouldError()
        {
            TestMaterializerContext context = new TestMaterializerContext();
            ComplexTypeWithPrimitiveCollection complexInstance = new ComplexTypeWithPrimitiveCollection();
            ODataProperty property = new ODataProperty() { Name = "Strings", Value = new ODataComplexValue() };

            Action test = () => this.CreatePrimitiveValueMaterializationPolicy(context).ApplyDataValue(context.ResolveTypeForMaterialization(typeof(ComplexTypeWithPrimitiveCollection), null), property, complexInstance);
            test.ShouldThrow<InvalidOperationException>().WithMessage(DSClient.Strings.AtomMaterializer_InvalidCollectionItem(property.Name));
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:9,代码来源:ComplexValueMaterializationPolicyTests.cs


示例12: ComplexTypeRoundtripAtomTest

        public void ComplexTypeRoundtripAtomTest()
        {
            var age = new ODataProperty() { Name = "Age", Value = (Int16)18 };
            var email = new ODataProperty() { Name = "Email", Value = "[email protected]" };
            var tel = new ODataProperty() { Name = "Tel", Value = "0123456789" };
            var id = new ODataProperty() { Name = "ID", Value = Guid.Empty };

            ODataComplexValue complexValue = new ODataComplexValue() { TypeName = "NS.PersonalInfo", Properties = new[] { age, email, tel, id } };

            this.VerifyComplexTypeRoundtrip(complexValue, "NS.PersonalInfo");
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:11,代码来源:NonPrimitiveTypeRoundtripAtomTests.cs


示例13: MaterializeEnumTypeProperty

        /// <summary>
        /// Materializes the enum data value.
        /// </summary>
        /// <param name="valueType">Type of the collection item.</param>
        /// <param name="property">The ODataProperty.</param>
        /// <returns>Materialized enum data CLR value.</returns>
        public object MaterializeEnumTypeProperty(Type valueType, ODataProperty property)
        {
            object materializedValue = null;
            ODataEnumValue value = property.Value as ODataEnumValue;
            this.MaterializeODataEnumValue(valueType, value.TypeName, value.Value, () => "TODO: Is this reachable?", out materializedValue);
            if (!property.HasMaterializedValue())
            {
                property.SetMaterializedValue(materializedValue);
            }

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


示例14: ShouldBeAbleToWriteInstanceAnnotationsInResponse

 public void ShouldBeAbleToWriteInstanceAnnotationsInResponse()
 {
     ODataProperty property = new ODataProperty()
     {
         Name = "Prop",
         Value = Guid.Empty,
         InstanceAnnotations = new Collection<ODataInstanceAnnotation>
         {
             new ODataInstanceAnnotation("Annotation.1", new ODataPrimitiveValue(true)),
             new ODataInstanceAnnotation("Annotation.2", new ODataPrimitiveValue(123))
         }
     };
     WriteAndValidate(outputContext => outputContext.WriteProperty(property), "{\"@odata.context\":\"http://odata.org/test/$metadata#Edm.Guid\",\"@Annotation.1\":true,\"@Annotation.2\":123,\"value\":\"00000000-0000-0000-0000-000000000000\"}");
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:14,代码来源:ODataJsonLightOutputContextTests.cs


示例15: ApplyProperty

        internal static void ApplyProperty(ODataProperty property, IEdmStructuredTypeReference resourceType, object resource,
            ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext)
        {
            IEdmProperty edmProperty = resourceType.FindProperty(property.Name);

            // try to deserializer the dynamic properties for open type.
            if (edmProperty == null)
            {
                // the logic here works for open complex type and open entity type.
                IEdmStructuredType structuredType = resourceType.StructuredDefinition();
                if (structuredType != null && structuredType.IsOpen)
                {
                    if (ApplyDynamicProperty(property, structuredType, resource, deserializerProvider, readContext))
                    {
                        return;
                    }
                }
            }

            string propertyName = property.Name;
            if (edmProperty != null)
            {
                propertyName = EdmLibHelpers.GetClrPropertyName(edmProperty, readContext.Model);
            }
            IEdmTypeReference propertyType = edmProperty != null ? edmProperty.Type : null; // open properties have null values

            EdmTypeKind propertyKind;
            object value = ConvertValue(property.Value, ref propertyType, deserializerProvider, readContext, out propertyKind);

            if (propertyKind == EdmTypeKind.Collection)
            {
                SetCollectionProperty(resource, edmProperty, value, propertyName);
            }
            else
            {
                if (!readContext.IsUntyped)
                {
                    if (propertyKind == EdmTypeKind.Primitive)
                    {
                        value = EdmPrimitiveHelpers.ConvertPrimitiveValue(value, GetPropertyType(resource, propertyName));
                    }
                    else if (propertyKind == EdmTypeKind.Enum)
                    {
                        value = EnumDeserializationHelpers.ConvertEnumValue(value, GetPropertyType(resource, propertyName));
                    }
                }

                SetProperty(resource, propertyName, value);
            }
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:50,代码来源:DeserializationHelpers.cs


示例16: PropertyGettersAndSettersTest

        public void PropertyGettersAndSettersTest()
        {
            string name1 = "ODataPrimitiveProperty";
            object value1 = "Hello world";

            ODataProperty primitiveProperty = new ODataProperty()
            {
                Name = name1,
                Value = value1,
            };

            this.Assert.AreEqual(name1, primitiveProperty.Name, "Expected equal name values.");
            this.Assert.AreSame(value1, primitiveProperty.Value, "Expected reference equal values for property 'Value'.");

            string name2 = "ODataComplexProperty";
            ODataComplexValue value2 = new ODataComplexValue()
            {
                Properties = new[]
                {
                    new ODataProperty() { Name = "One", Value = 1 },
                    new ODataProperty() { Name = "Two", Value = 2 },
                }
            };

            ODataProperty complexProperty = new ODataProperty()
            {
                Name = name2,
                Value = value2,
            };

            this.Assert.AreEqual(name2, complexProperty.Name, "Expected equal name values.");
            this.Assert.AreSame(value2, complexProperty.Value, "Expected reference equal values for property 'Value'.");

            string name3 = "ODataCollectionProperty";
            ODataCollectionValue value3 = new ODataCollectionValue()
            {
                Items = new[] { 1, 2, 3 }
            };

            ODataProperty multiValueProperty = new ODataProperty()
            {
                Name = name3,
                Value = value3,
            };

            this.Assert.AreEqual(name3, multiValueProperty.Name, "Expected equal name values.");
            this.Assert.AreSame(value3, multiValueProperty.Value, "Expected reference equal values for property 'Value'.");
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:48,代码来源:ODataPropertyTests.cs


示例17: ValidateStreamReferenceProperty

        /// <summary>
        /// Validates a stream reference property.
        /// </summary>
        /// <param name="streamProperty">The stream property to check.</param>
        /// <param name="structuredType">The owning type of the stream property or null if no metadata is available.</param>
        /// <param name="streamEdmProperty">The stream property defined by the model.</param>
        /// <param name="messageReaderSettings">The message reader settings being used.</param>
        internal static void ValidateStreamReferenceProperty(ODataProperty streamProperty, IEdmStructuredType structuredType, IEdmProperty streamEdmProperty, ODataMessageReaderSettings messageReaderSettings)
        {
            Debug.Assert(streamProperty != null, "streamProperty != null");

            ValidationUtils.ValidateStreamReferenceProperty(streamProperty, streamEdmProperty);

            if (structuredType != null && structuredType.IsOpen)
            {
                // If no property match was found in the metadata and an error wasn't raised, 
                // it is an open property (which is not supported for streams).
                if (streamEdmProperty == null && !messageReaderSettings.ReportUndeclaredLinkProperties)
                {
                    // Fails with the correct error message.
                    ValidationUtils.ValidateOpenPropertyValue(streamProperty.Name, streamProperty.Value);
                }
            }
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:24,代码来源:ReaderValidationUtils.cs


示例18: ReadInline_Calls_ReadPrimitive

        public void ReadInline_Calls_ReadPrimitive()
        {
            // Arrange
            IEdmPrimitiveTypeReference primitiveType = EdmCoreModel.Instance.GetInt32(isNullable: true);
            Mock<ODataPrimitiveDeserializer> deserializer = new Mock<ODataPrimitiveDeserializer>();
            ODataProperty property = new ODataProperty();
            ODataDeserializerContext readContext = new ODataDeserializerContext();

            deserializer.Setup(d => d.ReadPrimitive(property, readContext)).Returns(42).Verifiable();

            // Act
            var result = deserializer.Object.ReadInline(property, primitiveType, readContext);

            // Assert
            deserializer.Verify();
            Assert.Equal(42, result);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:17,代码来源:ODataPrimitiveDeserializerTests.cs


示例19: EntryStarting

        private void EntryStarting(WritingEntryArgs ea)
        {
            var odataProps = ea.Entry.Properties as List<ODataProperty>;

            var entityState = contextWrapper.Context.Entities.First(e => e.Entity == ea.Entity).State;

            // Send up an undeclared property on an Open Type.
            if (entityState == EntityStates.Modified || entityState == EntityStates.Added)
            {
                if (ea.Entity.GetType() == typeof(Row))
                {
                    // In practice, the data from this undeclared property would probably be stored in a transient property of the partial companion class to the client proxy.
                    var undeclaredOdataProperty = new ODataProperty() { Name = "dynamicPropertyKey", Value = "dynamicPropertyValue" };
                    odataProps.Add(undeclaredOdataProperty);
                }
            }
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:17,代码来源:ClientOpenTypeUpdateTests.cs


示例20: PropertyGettersAndSettersTest

        public void PropertyGettersAndSettersTest()
        {
            string etag = "ETag";
            Uri id = new Uri("http://odatalib.org/id");
            Uri readlink = new Uri("http://odatalib.org/readlink");
            Uri editlink = new Uri("http://odatalib.org/editlink");
            ODataStreamReferenceValue mediaResource = new ODataStreamReferenceValue();

            ODataProperty primitiveProperty = new ODataProperty();
            ODataProperty complexProperty = new ODataProperty();
            ODataProperty multiValueProperty = new ODataProperty();
            ODataProperty namedStreamProperty = new ODataProperty();
            List<ODataProperty> properties = new List<ODataProperty>()
            {
                primitiveProperty,
                complexProperty,
                multiValueProperty,
                namedStreamProperty
            };

            string typeName = "ODataLibSample.DummyType";

            ODataEntry entry = new ODataEntry()
            {
                ETag = etag,
                Id = id,
                EditLink = editlink,
                Properties = properties,
                TypeName = typeName,
                MediaResource = mediaResource
            };

            this.Assert.IsNull(entry.ReadLink, "Expect ReadLink to be null if it was not set.");

            entry.ReadLink = readlink;

            this.Assert.AreSame(etag, entry.ETag, "Expected reference equal values for property 'ETag'.");
            this.Assert.AreSame(id, entry.Id, "Expected reference equal values for property 'Id'.");
            this.Assert.AreSame(readlink, entry.ReadLink, "Expected reference equal values for property 'ReadLink'.");
            this.Assert.AreSame(editlink, entry.EditLink, "Expected reference equal values for property 'EditLink'.");
            this.Assert.AreSame(properties, entry.Properties, "Expected reference equal values for property 'Properties'.");
            this.Assert.AreSame(typeName, entry.TypeName, "Expected reference equal values for property 'TypeName'.");
            this.Assert.AreSame(mediaResource, entry.MediaResource, "Expected reference equals for property 'MediaResource'.");
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:44,代码来源:ODataEntryTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Core.ODataWriter类代码示例发布时间:2022-05-26
下一篇:
C# Core.ODataNavigationLink类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap