Esempio n. 1
0
        public override object ReadInline(ODataFeed feed, ODataDeserializerContext readContext)
        {
            if (readContext == null)
            {
                throw Error.ArgumentNull("readContext");
            }

            if (feed == null)
            {
                return(null);
            }

            ODataEntryDeserializer deserializer = DeserializerProvider.GetODataDeserializer(_edmEntityType);
            IList feedValue = CreateNewCollection(EdmLibHelpers.GetClrType(_edmEntityType, EdmModel));

            ODataFeedAnnotation feedAnnotation = feed.GetAnnotation <ODataFeedAnnotation>();

            Contract.Assert(feedAnnotation != null, "Each feed we create should gave annotation on it.");

            foreach (ODataEntry entry in feedAnnotation)
            {
                ODataEntryAnnotation annotation = entry.GetAnnotation <ODataEntryAnnotation>();
                Contract.Assert(annotation != null);

                feedValue.Add(deserializer.ReadInline(entry, readContext));
            }

            return(feedValue);
        }
Esempio n. 2
0
        private static object ConvertCollectionValue(ODataCollectionValue collection, IEdmTypeReference propertyType, ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext)
        {
            IEdmCollectionTypeReference collectionType = propertyType as IEdmCollectionTypeReference;

            Contract.Assert(collectionType != null, "The type for collection must be a IEdmCollectionType.");

            ODataEntryDeserializer deserializer = deserializerProvider.GetODataDeserializer(collectionType);

            return(deserializer.ReadInline(collection, readContext));
        }
        public void ReadInline_ThrowsArgument_TypeMismatch(Type deserializerType)
        {
            ODataEntryDeserializer deserializer = GetType().GetMethod("CreateDeserializer").MakeGenericMethod(deserializerType).Invoke(null, null) as ODataEntryDeserializer;

            ArgumentException ex = Assert.ThrowsArgument(
                () => deserializer.ReadInline("type mismatch item", new ODataDeserializerContext()),
                "item");

            Assert.True(ex.Message.StartsWith(String.Format("The argument must be of type '{0}'.", deserializerType.Name)));
        }
Esempio n. 4
0
 private object Convert(object value, IEdmTypeReference parameterType, ODataDeserializerContext readContext)
 {
     if (parameterType.IsPrimitive())
     {
         return(value);
     }
     else
     {
         ODataEntryDeserializer deserializer = _provider.GetODataDeserializer(parameterType);
         return(deserializer.ReadInline(value, readContext));
     }
 }
        private object CreateNestedEntityAndApplyProperties(ODataEntry entry, IEdmEntityTypeReference elementType, ODataDeserializerReadContext readContext)
        {
            ODataEntryAnnotation annotation = entry.GetAnnotation <ODataEntryAnnotation>();

            Contract.Assert(annotation != null);

            CreateEntityResource(annotation, elementType, readContext);

            ODataEntryDeserializer deserializer = DeserializerProvider.GetODataDeserializer(elementType);

            return(deserializer.ReadInline(entry, readContext));
        }
Esempio n. 6
0
        private void ApplyEntryInNavigationProperty(IEdmNavigationProperty navigationProperty, object entityResource, ODataEntry entry, ODataDeserializerContext readContext)
        {
            Contract.Assert(navigationProperty != null && navigationProperty.PropertyKind == EdmPropertyKind.Navigation, "navigationProperty != null && navigationProperty.TypeKind == ResourceTypeKind.EntityType");
            Contract.Assert(entityResource != null, "entityResource != null");

            ODataEntryDeserializer deserializer = DeserializerProvider.GetODataDeserializer(navigationProperty.Type);
            object value = deserializer.ReadInline(entry, readContext);

            if (readContext.IsPatchMode)
            {
                throw Error.InvalidOperation(SRResources.CannotPatchNavigationProperties, navigationProperty.Name, navigationProperty.DeclaringEntityType().FullName());
            }

            SetProperty(entityResource, navigationProperty.Name, isDelta: false, value: value);
        }
        private IEnumerable ReadItems(ODataFeed feed, ODataDeserializerContext readContext)
        {
            ODataEntryDeserializer deserializer = DeserializerProvider.GetODataDeserializer(_edmEntityType);

            ODataFeedAnnotation feedAnnotation = feed.GetAnnotation<ODataFeedAnnotation>();
            Contract.Assert(feedAnnotation != null, "Each feed we create should gave annotation on it.");

            foreach (ODataEntry entry in feedAnnotation)
            {
                ODataEntryAnnotation annotation = entry.GetAnnotation<ODataEntryAnnotation>();
                Contract.Assert(annotation != null);

                yield return deserializer.ReadInline(entry, readContext);
            }
        }
Esempio n. 8
0
        private void ApplyFeedInNavigationProperty(IEdmNavigationProperty navigationProperty, object entityResource, ODataFeed feed, ODataDeserializerContext readContext)
        {
            ODataFeedAnnotation feedAnnotation = feed.GetAnnotation <ODataFeedAnnotation>();

            Contract.Assert(feedAnnotation != null, "Each feed we create should gave annotation on it.");

            ODataEntryDeserializer deserializer = DeserializerProvider.GetODataDeserializer(navigationProperty.Type);
            object value = deserializer.ReadInline(feed, readContext);

            if (readContext.IsPatchMode)
            {
                throw Error.InvalidOperation(SRResources.CannotPatchNavigationProperties, navigationProperty.Name, navigationProperty.DeclaringEntityType().FullName());
            }

            SetProperty(entityResource, navigationProperty.Name, isDelta: false, value: value);
        }
Esempio n. 9
0
        private static object ConvertComplexValue(ODataComplexValue complexValue, ref IEdmTypeReference propertyType, ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext)
        {
            IEdmComplexTypeReference edmComplexType;

            if (propertyType == null)
            {
                // open complex property
                Contract.Assert(!String.IsNullOrEmpty(complexValue.TypeName), "ODataLib should have verified that open complex value has a type name since we provided metadata.");
                IEdmType edmType = deserializerProvider.EdmModel.FindType(complexValue.TypeName);
                Contract.Assert(edmType.TypeKind == EdmTypeKind.Complex, "ODataLib should have verified that complex value has a complex resource type.");
                edmComplexType = new EdmComplexTypeReference(edmType as IEdmComplexType, isNullable: true);
            }
            else
            {
                edmComplexType = propertyType.AsComplex();
            }

            ODataEntryDeserializer deserializer = deserializerProvider.GetODataDeserializer(edmComplexType);

            return(deserializer.ReadInline(complexValue, readContext));
        }
        private IEnumerable ReadItems(ODataCollectionValue collection, ODataDeserializerContext readContext)
        {
            RecurseEnter(readContext);

            IEdmTypeReference      elementType  = _edmCollectionType.ElementType();
            ODataEntryDeserializer deserializer = DeserializerProvider.GetODataDeserializer(elementType);

            Contract.Assert(deserializer != null);

            foreach (object entry in collection.Items)
            {
                if (elementType.IsPrimitive())
                {
                    yield return(entry);
                }
                else
                {
                    yield return(deserializer.ReadInline(entry, readContext));
                }
            }

            RecurseLeave(readContext);
        }
        public override object ReadInline(ODataCollectionValue collection, ODataDeserializerContext readContext)
        {
            if (readContext == null)
            {
                throw Error.ArgumentNull("readContext");
            }

            if (collection == null)
            {
                return(null);
            }

            RecurseEnter(readContext);

            IEdmTypeReference      elementType  = _edmCollectionType.ElementType();
            ODataEntryDeserializer deserializer = DeserializerProvider.GetODataDeserializer(elementType);

            Contract.Assert(deserializer != null);

            IList collectionValue = CreateNewCollection(EdmLibHelpers.GetClrType(elementType, EdmModel));

            foreach (object entry in collection.Items)
            {
                if (elementType.IsPrimitive())
                {
                    collectionValue.Add(entry);
                }
                else
                {
                    collectionValue.Add(deserializer.ReadInline(entry, readContext));
                }
            }

            RecurseLeave(readContext);

            return(collectionValue);
        }