本文整理汇总了C#中Microsoft.OData.Core.ODataProperty.GetMaterializedValue方法的典型用法代码示例。如果您正苦于以下问题:C# ODataProperty.GetMaterializedValue方法的具体用法?C# ODataProperty.GetMaterializedValue怎么用?C# ODataProperty.GetMaterializedValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Core.ODataProperty
的用法示例。
在下文中一共展示了ODataProperty.GetMaterializedValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyDataValue
//.........这里部分代码省略.........
throw DSClient.Error.InvalidOperation(DSClient.Strings.AtomMaterializer_InvalidCollectionItem(property.Name));
}
// ODataLib already parsed the data and materialized all the primitive types. There is nothing more to materialize
// anymore. Only complex type instance and collection instances need to be materialized, but those will be
// materialized later on.
// We need to materialize items before we change collectionInstance since this may throw. If we tried materializing
// after the Collection is wiped or created we would leave the object in half constructed state.
object collectionInstance = prop.GetValue(instance);
if (collectionInstance == null)
{
collectionInstance = this.CollectionValueMaterializationPolicy.CreateCollectionPropertyInstance(property, prop.PropertyType);
// allowAdd is false - we need to assign instance as the new property value
prop.SetValue(instance, collectionInstance, property.Name, false /* allowAdd? */);
}
else
{
// Clear existing Collection
prop.ClearBackingICollectionInstance(collectionInstance);
}
bool isElementNullable = prop.EdmProperty.Type.AsCollection().ElementType().IsNullable;
this.CollectionValueMaterializationPolicy.ApplyCollectionDataValues(
property,
collectionInstance,
prop.PrimitiveOrComplexCollectionItemType,
prop.AddValueToBackingICollectionInstance,
isElementNullable);
}
else if ((enumTypeTmp = Nullable.GetUnderlyingType(prop.NullablePropertyType) ?? prop.NullablePropertyType) != null
&& enumTypeTmp.IsEnum())
{
ODataEnumValue enumValue = property.Value as ODataEnumValue;
object tmpValue = EnumValueMaterializationPolicy.MaterializeODataEnumValue(enumTypeTmp, enumValue);
// TODO: 1. use EnumValueMaterializationPolicy 2. handle nullable enum property
prop.SetValue(instance, tmpValue, property.Name, false /* allowAdd? */);
}
else
{
object propertyValue = property.Value;
ODataComplexValue complexValue = propertyValue as ODataComplexValue;
if (propertyValue != null && complexValue != null)
{
if (!prop.EdmProperty.Type.IsComplex())
{
// The error message is a bit odd, but it's compatible with V1.
throw DSClient.Error.InvalidOperation(DSClient.Strings.Deserialize_ExpectingSimpleValue);
}
// Complex type.
bool needToSet = false;
ClientEdmModel edmModel = this.MaterializerContext.Model;
ClientTypeAnnotation complexType = edmModel.GetClientTypeAnnotation(edmModel.GetOrCreateEdmType(prop.PropertyType));
object complexInstance = prop.GetValue(instance);
// Validating property inheritance in complexvalue and instance
if (prop.PropertyType.Name != property.Name)
{
complexType = this.MaterializerContext.ResolveTypeForMaterialization(prop.PropertyType, complexValue.TypeName);
// recreate complexInstance with derived type
complexInstance = null;
}
if (complexValue.Properties.Any() || complexInstance == null)
{
complexInstance = this.CreateNewInstance(complexType.EdmTypeReference, complexType.ElementType);
needToSet = true;
}
this.MaterializeDataValues(complexType, complexValue.Properties, this.MaterializerContext.IgnoreMissingProperties);
this.ApplyDataValues(complexType, complexValue.Properties, complexInstance);
if (needToSet)
{
prop.SetValue(instance, complexInstance, property.Name, true /* allowAdd? */);
}
if (!this.MaterializerContext.Context.DisableInstanceAnnotationMaterialization)
{
// Set instance annotation for this complex instance
this.InstanceAnnotationMaterializationPolicy.SetInstanceAnnotations(property, complexInstance);
}
}
else
{
this.MaterializePrimitiveDataValue(prop.NullablePropertyType, property);
prop.SetValue(instance, property.GetMaterializedValue(), property.Name, true /* allowAdd? */);
}
}
if (!this.MaterializerContext.Context.DisableInstanceAnnotationMaterialization)
{
// Apply instance annotation for Property
this.InstanceAnnotationMaterializationPolicy.SetInstanceAnnotations(property, type.ElementType, instance);
}
}