Esempio n. 1
0
 private static ClientTypeAnnotation GetPropertyType(ClientTypeAnnotation clientType, string propertyName)
 {
     ClientPropertyAnnotation property = clientType.GetProperty(propertyName, true);
     if (property == null)
     {
         throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.EpmSourceTree_InaccessiblePropertyOnType(propertyName, clientType.ElementTypeName));
     }
     if (property.IsStreamLinkProperty)
     {
         throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.EpmSourceTree_NamedStreamCannotBeMapped(propertyName, clientType.ElementTypeName));
     }
     if (property.IsSpatialType)
     {
         throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.EpmSourceTree_SpatialTypeCannotBeMapped(propertyName, clientType.ElementTypeName));
     }
     if (property.IsPrimitiveOrComplexCollection)
     {
         throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.EpmSourceTree_CollectionPropertyCannotBeMapped(propertyName, clientType.ElementTypeName));
     }
     ClientEdmModel model = ClientEdmModel.GetModel(clientType.MaxProtocolVersion);
     IEdmType orCreateEdmType = model.GetOrCreateEdmType(property.PropertyType);
     return model.GetClientTypeAnnotation(orCreateEdmType);
 }
Esempio n. 2
0
 protected static void ApplyDataValue(ClientTypeAnnotation type, ODataProperty property, bool ignoreMissingProperties, System.Data.Services.Client.ResponseInfo responseInfo, object instance)
 {
     ClientPropertyAnnotation annotation = type.GetProperty(property.Name, ignoreMissingProperties);
     if (annotation != null)
     {
         if (annotation.IsPrimitiveOrComplexCollection)
         {
             if (property.Value == null)
             {
                 throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Collection_NullCollectionNotSupported(property.Name));
             }
             if (property.Value is string)
             {
                 throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Deserialize_MixedTextWithComment);
             }
             if (property.Value is ODataComplexValue)
             {
                 throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.AtomMaterializer_InvalidCollectionItem(property.Name));
             }
             object obj2 = annotation.GetValue(instance);
             if (obj2 == null)
             {
                 obj2 = CreateCollectionInstance(property, annotation.PropertyType, responseInfo);
                 annotation.SetValue(instance, obj2, property.Name, false);
             }
             else
             {
                 annotation.ClearBackingICollectionInstance(obj2);
             }
             ApplyCollectionDataValues(property, ignoreMissingProperties, responseInfo, obj2, annotation.PrimitiveOrComplexCollectionItemType, new Action<object, object>(annotation.AddValueToBackingICollectionInstance));
         }
         else
         {
             object obj3 = property.Value;
             ODataComplexValue value2 = obj3 as ODataComplexValue;
             if ((obj3 != null) && (value2 != null))
             {
                 if (!annotation.EdmProperty.Type.IsComplex())
                 {
                     throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Deserialize_ExpectingSimpleValue);
                 }
                 bool flag = false;
                 ClientEdmModel model = ClientEdmModel.GetModel(responseInfo.MaxProtocolVersion);
                 ClientTypeAnnotation clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(annotation.PropertyType));
                 object obj4 = annotation.GetValue(instance);
                 if (obj4 == null)
                 {
                     obj4 = clientTypeAnnotation.CreateInstance();
                     flag = true;
                 }
                 MaterializeDataValues(clientTypeAnnotation, value2.Properties, ignoreMissingProperties);
                 ApplyDataValues(clientTypeAnnotation, value2.Properties, ignoreMissingProperties, responseInfo, obj4);
                 if (flag)
                 {
                     annotation.SetValue(instance, obj4, property.Name, true);
                 }
             }
             else
             {
                 MaterializePrimitiveDataValue(annotation.NullablePropertyType, property);
                 annotation.SetValue(instance, property.GetMaterializedValue(), property.Name, true);
             }
         }
     }
 }
Esempio n. 3
0
 protected static void MaterializeDataValues(ClientTypeAnnotation actualType, IEnumerable<ODataProperty> values, bool ignoreMissingProperties)
 {
     foreach (ODataProperty property in values)
     {
         if (!(property.Value is ODataStreamReferenceValue))
         {
             string name = property.Name;
             ClientPropertyAnnotation annotation = actualType.GetProperty(name, ignoreMissingProperties);
             if (annotation != null)
             {
                 if (ClientTypeUtil.TypeOrElementTypeIsEntity(annotation.PropertyType))
                 {
                     throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.AtomMaterializer_InvalidEntityType(annotation.EntityCollectionItemType ?? annotation.PropertyType));
                 }
                 if (annotation.IsKnownType)
                 {
                     MaterializePrimitiveDataValue(annotation.NullablePropertyType, property);
                 }
             }
         }
     }
 }