當前位置: 首頁>>代碼示例>>C#>>正文


C# Core.ODataProperty類代碼示例

本文整理匯總了C#中Microsoft.OData.Core.ODataProperty的典型用法代碼示例。如果您正苦於以下問題:C# ODataProperty類的具體用法?C# ODataProperty怎麽用?C# ODataProperty使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ODataProperty類屬於Microsoft.OData.Core命名空間,在下文中一共展示了ODataProperty類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的Microsoft.OData.Core.ODataProperty類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。