Esempio n. 1
0
 protected static void ApplyCollectionDataValues(ODataProperty collectionProperty, bool ignoreMissingProperties, System.Data.Services.Client.ResponseInfo responseInfo, object collectionInstance, Type collectionItemType, Action<object, object> AddValueToBackingICollectionInstance)
 {
     ODataCollectionValue value2 = collectionProperty.Value as ODataCollectionValue;
     if (value2.Items != null)
     {
         bool flag = PrimitiveType.IsKnownNullableType(collectionItemType);
         ClientEdmModel model = ClientEdmModel.GetModel(responseInfo.MaxProtocolVersion);
         foreach (object obj2 in value2.Items)
         {
             if (obj2 == null)
             {
                 throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Collection_NullCollectionItemsNotSupported);
             }
             if (flag)
             {
                 object obj3;
                 if ((obj2 is ODataComplexValue) || (obj2 is ODataCollectionValue))
                 {
                     throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Collection_ComplexTypesInCollectionOfPrimitiveTypesNotAllowed);
                 }
                 MaterializePrimitiveDataValue(collectionItemType, value2.TypeName, obj2, responseInfo, () => System.Data.Services.Client.Strings.Collection_NullCollectionItemsNotSupported, out obj3);
                 AddValueToBackingICollectionInstance(collectionInstance, ConvertPrimitiveValue(obj2, collectionItemType));
             }
             else
             {
                 ODataComplexValue value3 = obj2 as ODataComplexValue;
                 if (value3 == null)
                 {
                     throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Collection_PrimitiveTypesInCollectionOfComplexTypesNotAllowed);
                 }
                 ClientTypeAnnotation clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(collectionItemType));
                 object instance = clientTypeAnnotation.CreateInstance();
                 ApplyDataValues(clientTypeAnnotation, value3.Properties, ignoreMissingProperties, responseInfo, instance);
                 AddValueToBackingICollectionInstance(collectionInstance, instance);
             }
         }
     }
     collectionProperty.SetMaterializedValue(collectionInstance);
 }
Esempio n. 2
0
 protected static void MaterializePrimitiveDataValue(Type type, ODataProperty property)
 {
     if (!property.HasMaterializedValue())
     {
         object materializedValue = ConvertPrimitiveValue(property.Value, type);
         property.SetMaterializedValue(materializedValue);
     }
 }