/// <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; }
/// <summary> /// Applies collectionValue item to the provided <paramref name="collectionInstance"/>. /// </summary> /// <param name="collectionProperty">Atom property containing materialized Collection items.</param> /// <param name="collectionInstance">Collection instance. Must implement ICollection<T> where T is either primitive or complex type (not an entity).</param> /// <param name="collectionItemType">Type of items in the Collection. Note: this could be calculated from collectionInstance but we already have it in upstream methods.</param> /// <param name="addValueToBackingICollectionInstance">Action called actually add a Collection item to <paramref name="collectionInstance" /></param> /// <param name="isElementNullable">If element type is nullable.</param> internal void ApplyCollectionDataValues( ODataProperty collectionProperty, object collectionInstance, Type collectionItemType, Action<object, object> addValueToBackingICollectionInstance, bool isElementNullable) { Debug.Assert(collectionProperty != null, "property != null"); Debug.Assert(collectionProperty.Value != null, "Collection should have already been checked for nullness"); Debug.Assert(collectionInstance != null, "collectionInstance != null"); Debug.Assert(WebUtil.IsCLRTypeCollection(collectionInstance.GetType(), this.materializerContext.Model), "collectionInstance must be a CollectionValue"); Debug.Assert(collectionItemType.IsAssignableFrom( ClientTypeUtil.GetImplementationType(collectionInstance.GetType(), typeof(ICollection<>)).GetGenericArguments()[0]), "collectionItemType has to match the collectionInstance generic type."); Debug.Assert(!ClientTypeUtil.TypeIsEntity(collectionItemType, this.materializerContext.Model), "CollectionValues cannot contain entities"); Debug.Assert(addValueToBackingICollectionInstance != null, "AddValueToBackingICollectionInstance != null"); ODataCollectionValue collectionValue = collectionProperty.Value as ODataCollectionValue; this.ApplyCollectionDataValues( collectionValue.Items, collectionValue.TypeName, collectionInstance, collectionItemType, addValueToBackingICollectionInstance, isElementNullable); collectionProperty.SetMaterializedValue(collectionInstance); }
/// <summary>Materializes a primitive value. No op for non-primitive values.</summary> /// <param name="type">Type of value to set.</param> /// <param name="property">Property holding value.</param> internal void MaterializePrimitiveDataValue(Type type, ODataProperty property) { Debug.Assert(type != null, "type != null"); Debug.Assert(property != null, "atomProperty != null"); if (!property.HasMaterializedValue()) { object value = property.Value; object materializedValue = this.PrimitivePropertyConverter.ConvertPrimitiveValue(value, type); property.SetMaterializedValue(materializedValue); } }