本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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();
}
示例6: ShouldBeAbleToSetThePropertySerializationInfo
public void ShouldBeAbleToSetThePropertySerializationInfo()
{
ODataProperty property = new ODataProperty();
ODataPropertySerializationInfo serializationInfo = new ODataPropertySerializationInfo();
property.SetSerializationInfo(serializationInfo);
property.SerializationInfo.Should().BeSameAs(serializationInfo);
}
示例7: ShouldBeAbleToClearThePropertySerializationInfo
public void ShouldBeAbleToClearThePropertySerializationInfo()
{
ODataProperty property = new ODataProperty();
ODataPropertySerializationInfo serializationInfo = new ODataPropertySerializationInfo();
property.SerializationInfo = serializationInfo;
property.SetSerializationInfo(null);
property.SerializationInfo.Should().BeNull();
}
示例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);
}
示例9: CreateProperty
private static ODataProperty CreateProperty(string name, object value)
{
ODataProperty prop = new ODataProperty()
{
Name = name,
Value = value,
};
return prop;
}
示例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;
}
示例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));
}
示例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");
}
示例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;
}
示例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\"}");
}
示例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);
}
}