internal static void RecurseEnter(ODataDeserializerReadContext readContext)
 {
     if (!readContext.IncrementCurrentReferenceDepth())
     {
         throw Error.InvalidOperation(SRResources.RecursionLimitExceeded);
     }
 }
 internal static void RecurseEnter(ODataDeserializerReadContext readContext)
 {
     if (!readContext.IncrementCurrentReferenceDepth())
     {
         throw Error.InvalidOperation(SRResources.RecursionLimitExceeded);
     }
 }
        public override object Read(ODataMessageReader messageReader, ODataDeserializerReadContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull("messageReader");
            }

            object value = messageReader.ReadValue(PrimitiveTypeReference);

            // TODO: Bug 467612: do value conversions here.
            return value;
        }
Exemple #4
0
        public override object Read(ODataMessageReader messageReader, ODataDeserializerReadContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull("messageReader");
            }

            object value = messageReader.ReadValue(PrimitiveTypeReference);

            // TODO: Bug 467612: do value conversions here.
            return(value);
        }
        public override object Read(ODataMessageReader messageReader, ODataDeserializerReadContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull("messageReader");
            }

            ODataEntityReferenceLink entityReferenceLink = messageReader.ReadEntityReferenceLink();
            if (entityReferenceLink != null)
            {
                return entityReferenceLink.Url;
            }

            return null;
        }
        public override object Read(ODataMessageReader messageReader, ODataDeserializerReadContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull("messageReader");
            }

            ODataEntityReferenceLink entityReferenceLink = messageReader.ReadEntityReferenceLink();

            if (entityReferenceLink != null)
            {
                return(entityReferenceLink.Url);
            }

            return(null);
        }
        public override object Read(ODataMessageReader messageReader, ODataDeserializerReadContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull("messageReader");
            }

            if (readContext == null)
            {
                throw Error.ArgumentNull("readContext");
            }

            ODataReader odataReader   = messageReader.CreateODataEntryReader(EdmEntityType.EntityDefinition());
            ODataEntry  topLevelEntry = ReadEntry(odataReader, EdmEntityType, readContext);

            return(ReadInline(topLevelEntry, readContext));
        }
        internal static void ApplyProperty(ODataProperty property, IEdmStructuredTypeReference resourceType, object resource, ODataDeserializerProvider deserializerProvider, ODataDeserializerReadContext readContext)
        {
            IEdmProperty edmProperty = resourceType.FindProperty(property.Name);

            string propertyName = property.Name;
            IEdmTypeReference propertyType = edmProperty != null ? edmProperty.Type : null; // open properties have null values

            object value = ConvertValue(property.Value, ref propertyType, deserializerProvider, readContext);

            // If we are in patch mode and we are deserializing an entity object then we are updating Delta<T> and not T.
            if (!readContext.IsPatchMode || !resourceType.IsEntity())
            {
                resource.GetType().GetProperty(propertyName).SetValue(resource, value, index: null);
            }
            else
            {
                (resource as IDelta).TrySetPropertyValue(propertyName, value);
            }
        }
        public override object ReadInline(object item, ODataDeserializerReadContext readContext)
        {
            ODataEntry topLevelEntry = item as ODataEntry;

            if (item == null)
            {
                throw Error.Argument("item", SRResources.ItemMustBeOfType, typeof(ODataEntry).Name);
            }

            ODataEntryAnnotation topLevelEntryAnnotation = topLevelEntry.GetAnnotation <ODataEntryAnnotation>();

            Contract.Assert(topLevelEntryAnnotation != null);

            RecurseEnter(readContext);
            ApplyEntityProperties(topLevelEntry, topLevelEntryAnnotation, readContext);
            RecurseLeave(readContext);

            return(topLevelEntryAnnotation.EntityResource);
        }
        public override object ReadInline(object item, ODataDeserializerReadContext readContext)
        {
            ODataComplexValue complexValue = item as ODataComplexValue;
            if (complexValue == null)
            {
                throw Error.Argument("item", SRResources.ItemMustBeOfType, typeof(ODataComplexValue).Name);
            }

            RecurseEnter(readContext);

            object complexResource = CreateResource(EdmComplexType.ComplexDefinition(), EdmModel);
            foreach (ODataProperty complexProperty in complexValue.Properties)
            {
                ApplyProperty(complexProperty, EdmComplexType, complexResource, DeserializerProvider, readContext);
            }

            RecurseLeave(readContext);

            return complexResource;
        }
Exemple #11
0
        public override object ReadInline(object item, ODataDeserializerReadContext readContext)
        {
            ODataComplexValue complexValue = item as ODataComplexValue;

            if (complexValue == null)
            {
                throw Error.Argument("item", SRResources.ItemMustBeOfType, typeof(ODataComplexValue).Name);
            }

            RecurseEnter(readContext);

            object complexResource = CreateResource(EdmComplexType.ComplexDefinition(), EdmModel);

            foreach (ODataProperty complexProperty in complexValue.Properties)
            {
                ApplyProperty(complexProperty, EdmComplexType, complexResource, DeserializerProvider, readContext);
            }

            RecurseLeave(readContext);

            return(complexResource);
        }
 public virtual object ReadInline(object item, ODataDeserializerReadContext readContext)
 {
     throw Error.NotSupported(SRResources.DoesNotSupportReadInLine, GetType().Name);
 }
 private void ApplyValueProperties(ODataEntry entry, IEdmStructuredTypeReference entityType, object entityResource, ODataDeserializerReadContext readContext)
 {
     foreach (ODataProperty property in entry.Properties)
     {
         ApplyProperty(property, entityType, entityResource, DeserializerProvider, 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));
        }
        private void ApplyFeedInNavigationProperty(IEdmNavigationProperty navigationProperty, object entityResource, ODataFeed feed, ODataDeserializerReadContext readContext)
        {
            ODataFeedAnnotation feedAnnotation = feed.GetAnnotation <ODataFeedAnnotation>();

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

            IEdmEntityTypeReference elementType = ToEntityType(navigationProperty);

            foreach (ODataEntry entryInFeed in feedAnnotation)
            {
                object childEntityResource = CreateNestedEntityAndApplyProperties(entryInFeed, elementType, readContext);
                AddReferenceToCollection(entityResource, navigationProperty, childEntityResource);
            }
        }
        private static object ConvertCollectionValue(ODataCollectionValue collection, IEdmTypeReference propertyType, ODataDeserializerProvider deserializerProvider, ODataDeserializerReadContext readContext)
        {
            IEdmCollectionType collectionType = propertyType as IEdmCollectionType;
            Contract.Assert(collectionType != null, "The type for collection must be a IEdmCollectionType.");

            IList collectionList = CreateNewCollection();

            RecurseEnter(readContext);

            Contract.Assert(collection.Items != null, "The ODataLib reader should always populate the ODataCollectionValue.Items collection.");
            foreach (object odataItem in collection.Items)
            {
                IEdmTypeReference itemType = collectionType.ElementType;
                collectionList.Add(ConvertValue(odataItem, ref itemType, deserializerProvider, readContext));
            }

            RecurseLeave(readContext);

            return collectionList;
        }
        private static object ConvertCollectionValue(ODataCollectionValue collection, IEdmTypeReference propertyType, ODataDeserializerProvider deserializerProvider, ODataDeserializerReadContext readContext)
        {
            IEdmCollectionType collectionType = propertyType as IEdmCollectionType;

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

            IList collectionList = CreateNewCollection();

            RecurseEnter(readContext);

            Contract.Assert(collection.Items != null, "The ODataLib reader should always populate the ODataCollectionValue.Items collection.");
            foreach (object odataItem in collection.Items)
            {
                IEdmTypeReference itemType = collectionType.ElementType;
                collectionList.Add(ConvertValue(odataItem, ref itemType, deserializerProvider, readContext));
            }

            RecurseLeave(readContext);

            return(collectionList);
        }
        private static object ConvertComplexValue(ODataComplexValue complexValue, ref IEdmTypeReference propertyType, ODataDeserializerProvider deserializerProvider, ODataDeserializerReadContext 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 void ApplyNavigationProperties(ODataEntryAnnotation entryAnnotation, IEdmEntityTypeReference entityType, object entityResource, ODataDeserializerReadContext readContext)
        {
            Contract.Assert(entityType.TypeKind() == EdmTypeKind.Entity, "Only entity types can be specified for entities.");

            foreach (ODataNavigationLink navigationLink in entryAnnotation)
            {
                IEdmNavigationProperty navigationProperty = entityType.FindProperty(navigationLink.Name) as IEdmNavigationProperty;
                Contract.Assert(navigationProperty != null, "ODataLib reader should have already validated that all navigation properties are declared and none is open.");

                ApplyNavigationProperty(navigationLink, navigationProperty, entityResource, readContext);
            }
        }
        /// <inheritdoc/>
        public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {
            if (type == null)
            {
                throw Error.ArgumentNull("type");
            }

            if (readStream == null)
            {
                throw Error.ArgumentNull("readStream");
            }

            object result = null;

            HttpContentHeaders contentHeaders = content == null ? null : content.Headers;
            // If content length is 0 then return default value for this type
            if (contentHeaders != null && contentHeaders.ContentLength == 0)
            {
                result = GetDefaultValueForType(type);
            }
            else
            {
                bool isPatchMode = TryGetInnerTypeForDelta(ref type);
                ODataDeserializer deserializer = ODataDeserializerProvider.GetODataDeserializer(type);
                if (deserializer == null)
                {
                    throw Error.Argument("type", SRResources.FormatterReadIsNotSupportedForType, type.FullName, GetType().FullName);
                }

                ODataMessageReader oDataMessageReader = null;
                ODataMessageReaderSettings oDataReaderSettings = new ODataMessageReaderSettings { DisableMessageStreamDisposal = true };
                try
                {
                    if (IsClient)
                    {
                        IODataResponseMessage oDataResponseMessage = new ODataMessageWrapper(readStream, contentHeaders);
                        oDataMessageReader = new ODataMessageReader(oDataResponseMessage, oDataReaderSettings, ODataDeserializerProvider.EdmModel);
                    }
                    else
                    {
                        IODataRequestMessage oDataRequestMessage = new ODataMessageWrapper(readStream, contentHeaders);
                        oDataMessageReader = new ODataMessageReader(oDataRequestMessage, oDataReaderSettings, ODataDeserializerProvider.EdmModel);
                    }

                    ODataDeserializerReadContext readContext = new ODataDeserializerReadContext { IsPatchMode = isPatchMode };

                    result = deserializer.Read(oDataMessageReader, readContext);
                }
                finally
                {
                    if (oDataMessageReader != null)
                    {
                        oDataMessageReader.Dispose();
                    }
                }
            }

            return TaskHelpers.FromResult(result);
        }
        internal static void ApplyProperty(ODataProperty property, IEdmStructuredTypeReference resourceType, object resource, ODataDeserializerProvider deserializerProvider, ODataDeserializerReadContext readContext)
        {
            IEdmProperty edmProperty = resourceType.FindProperty(property.Name);

            string            propertyName = property.Name;
            IEdmTypeReference propertyType = edmProperty != null ? edmProperty.Type : null; // open properties have null values

            object value = ConvertValue(property.Value, ref propertyType, deserializerProvider, readContext);

            // If we are in patch mode and we are deserializing an entity object then we are updating Delta<T> and not T.
            if (!readContext.IsPatchMode || !resourceType.IsEntity())
            {
                resource.GetType().GetProperty(propertyName).SetValue(resource, value, index: null);
            }
            else
            {
                (resource as IDelta).TrySetPropertyValue(propertyName, value);
            }
        }
        internal static object ConvertValue(object oDataValue, ref IEdmTypeReference propertyType, ODataDeserializerProvider deserializerProvider, ODataDeserializerReadContext readContext)
        {
            if (oDataValue == null)
            {
                return null;
            }

            ODataComplexValue complexValue = oDataValue as ODataComplexValue;
            if (complexValue != null)
            {
                return ConvertComplexValue(complexValue, ref propertyType, deserializerProvider, readContext);
            }

            ODataCollectionValue collection = oDataValue as ODataCollectionValue;
            if (collection != null)
            {
                Contract.Assert(propertyType != null, "Open collection properties are not supported.");
                return ConvertCollectionValue(collection, propertyType, deserializerProvider, readContext);
            }

            return ConvertPrimitiveValue(oDataValue, ref propertyType);
        }
        private static object ConvertComplexValue(ODataComplexValue complexValue, ref IEdmTypeReference propertyType, ODataDeserializerProvider deserializerProvider, ODataDeserializerReadContext 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);
        }
 internal static void RecurseLeave(ODataDeserializerReadContext readContext)
 {
     readContext.DecrementCurrentReferenceDepth();
 }
        private ODataEntry ReadEntry(ODataReader odataReader, IEdmEntityTypeReference entityType, ODataDeserializerReadContext readContext)
        {
            ODataEntry        topLevelEntry = null;
            Stack <ODataItem> itemsStack    = new Stack <ODataItem>();

            while (odataReader.Read())
            {
                if (itemsStack.Count >= RecursionLimit)
                {
                    throw Error.InvalidOperation(SRResources.RecursionLimitExceeded);
                }

                switch (odataReader.State)
                {
                case ODataReaderState.EntryStart:
                    ODataEntry           entry           = (ODataEntry)odataReader.Item;
                    ODataEntryAnnotation entryAnnotation = null;
                    if (entry != null)
                    {
                        entryAnnotation = new ODataEntryAnnotation();
                        entry.SetAnnotation(entryAnnotation);
                    }

                    if (itemsStack.Count == 0)
                    {
                        Contract.Assert(entry != null, "The top-level entry can never be null.");
                        topLevelEntry = entry;

                        CreateEntityResource(entryAnnotation, entityType, readContext);
                    }
                    else
                    {
                        ODataItem parentItem = itemsStack.Peek();
                        ODataFeed parentFeed = parentItem as ODataFeed;
                        if (parentFeed != null)
                        {
                            ODataFeedAnnotation parentFeedAnnotation = parentFeed.GetAnnotation <ODataFeedAnnotation>();
                            Contract.Assert(parentFeedAnnotation != null, "Every feed we added to the stack should have the feed annotation on it.");
                            parentFeedAnnotation.Add(entry);
                        }
                        else
                        {
                            ODataNavigationLink           parentNavigationLink           = (ODataNavigationLink)parentItem;
                            ODataNavigationLinkAnnotation parentNavigationLinkAnnotation = parentNavigationLink.GetAnnotation <ODataNavigationLinkAnnotation>();
                            Contract.Assert(parentNavigationLinkAnnotation != null, "Every navigation link we added to the stack should have the navigation link annotation on it.");

                            Contract.Assert(parentNavigationLink.IsCollection == false, "Only singleton navigation properties can contain entry as their child.");
                            Contract.Assert(parentNavigationLinkAnnotation.Count == 0, "Each navigation property can contain only one entry as its direct child.");
                            parentNavigationLinkAnnotation.Add(entry);
                        }
                    }
                    itemsStack.Push(entry);
                    break;

                case ODataReaderState.EntryEnd:
                    Contract.Assert(itemsStack.Count > 0 && itemsStack.Peek() == odataReader.Item, "The entry which is ending should be on the top of the items stack.");
                    itemsStack.Pop();
                    break;

                case ODataReaderState.NavigationLinkStart:
                    ODataNavigationLink navigationLink = (ODataNavigationLink)odataReader.Item;
                    Contract.Assert(navigationLink != null, "Navigation link should never be null.");

                    navigationLink.SetAnnotation(new ODataNavigationLinkAnnotation());
                    Contract.Assert(itemsStack.Count > 0, "Navigation link can't appear as top-level item.");
                    {
                        ODataEntry           parentEntry           = (ODataEntry)itemsStack.Peek();
                        ODataEntryAnnotation parentEntryAnnotation = parentEntry.GetAnnotation <ODataEntryAnnotation>();
                        Contract.Assert(parentEntryAnnotation != null, "Every entry we added to the stack should have the navigation link annotation on it.");
                        parentEntryAnnotation.Add(navigationLink);
                    }

                    itemsStack.Push(navigationLink);
                    break;

                case ODataReaderState.NavigationLinkEnd:
                    Contract.Assert(itemsStack.Count > 0 && itemsStack.Peek() == odataReader.Item, "The navigation link which is ending should be on the top of the items stack.");
                    itemsStack.Pop();
                    break;

                case ODataReaderState.FeedStart:
                    ODataFeed feed = (ODataFeed)odataReader.Item;
                    Contract.Assert(feed != null, "Feed should never be null.");

                    feed.SetAnnotation(new ODataFeedAnnotation());
                    Contract.Assert(itemsStack.Count > 0, "Since we always start reading entry, we should never get a feed as the top-level item.");
                    {
                        ODataNavigationLink           parentNavigationLink           = (ODataNavigationLink)itemsStack.Peek();
                        ODataNavigationLinkAnnotation parentNavigationLinkAnnotation = parentNavigationLink.GetAnnotation <ODataNavigationLinkAnnotation>();
                        Contract.Assert(parentNavigationLinkAnnotation != null, "Every navigation link we added to the stack should have the navigation link annotation on it.");

                        Contract.Assert(parentNavigationLink.IsCollection == true, "Only collection navigation properties can contain feed as their child.");
                        parentNavigationLinkAnnotation.Add(feed);
                    }

                    itemsStack.Push(feed);
                    break;

                case ODataReaderState.FeedEnd:
                    Contract.Assert(itemsStack.Count > 0 && itemsStack.Peek() == odataReader.Item, "The feed which is ending should be on the top of the items stack.");
                    itemsStack.Pop();
                    break;

                case ODataReaderState.EntityReferenceLink:
                    ODataEntityReferenceLink entityReferenceLink = (ODataEntityReferenceLink)odataReader.Item;
                    Contract.Assert(entityReferenceLink != null, "Entity reference link should never be null.");

                    Contract.Assert(itemsStack.Count > 0, "Entity reference link should never be reported as top-level item.");
                    {
                        ODataNavigationLink           parentNavigationLink           = (ODataNavigationLink)itemsStack.Peek();
                        ODataNavigationLinkAnnotation parentNavigationLinkAnnotation = parentNavigationLink.GetAnnotation <ODataNavigationLinkAnnotation>();
                        Contract.Assert(parentNavigationLinkAnnotation != null, "Every navigation link we added to the stack should have the navigation link annotation on it.");

                        parentNavigationLinkAnnotation.Add(entityReferenceLink);
                    }

                    break;

                default:
                    Contract.Assert(false, "We should never get here, it means the ODataReader reported a wrong state.");
                    break;
                }
            }

            Contract.Assert(odataReader.State == ODataReaderState.Completed, "We should have consumed all of the input by now.");
            Contract.Assert(topLevelEntry != null, "A top level entry should have been read by now.");
            return(topLevelEntry);
        }
        private void ApplyNavigationProperty(ODataNavigationLink navigationLink, IEdmNavigationProperty navigationProperty, object entityResource, ODataDeserializerReadContext readContext)
        {
            ODataNavigationLinkAnnotation navigationLinkAnnotation = navigationLink.GetAnnotation <ODataNavigationLinkAnnotation>();

            Contract.Assert(navigationLinkAnnotation != null, "navigationLinkAnnotation != null");
            // Contract.Assert(navigationLinkAnnotation.Count > 0, "Each navigation link must have at least one child in request.");
            Contract.Assert(navigationLink.IsCollection.HasValue, "We should know the cardinality of the navigation link by now.");

            foreach (ODataItem childItem in navigationLinkAnnotation)
            {
                ODataEntityReferenceLink entityReferenceLink = childItem as ODataEntityReferenceLink;
                if (entityReferenceLink != null)
                {
                    ApplyEntityReferenceLinkInNavigationProperty(navigationProperty, entityResource, entityReferenceLink);
                    continue;
                }

                ODataFeed feed = childItem as ODataFeed;
                if (feed != null)
                {
                    ApplyFeedInNavigationProperty(navigationProperty, entityResource, feed, readContext);
                    continue;
                }

                // It must be entry by now.
                ODataEntry entry = (ODataEntry)childItem;
                ApplyEntryInNavigationProperty(navigationProperty, entityResource, entry, readContext);
            }
        }
 /// <summary>
 /// Read an <see cref="IODataRequestMessage"/> using messageReader
 /// </summary>
 /// <param name="messageReader">The messageReader to use</param>
 /// <param name="readContext">The read context</param>
 /// <returns></returns>
 public virtual object Read(ODataMessageReader messageReader, ODataDeserializerReadContext readContext)
 {
     throw Error.NotSupported(SRResources.DeserializerDoesNotSupportRead, GetType().Name);
 }
        private void ApplyEntryInNavigationProperty(IEdmNavigationProperty navigationProperty, object entityResource, ODataEntry entry, ODataDeserializerReadContext readContext)
        {
            Contract.Assert(navigationProperty != null && navigationProperty.PropertyKind == EdmPropertyKind.Navigation, "navigationProperty != null && navigationProperty.TypeKind == ResourceTypeKind.EntityType");
            Contract.Assert(entityResource != null, "entityResource != null");

            if (entry == null)
            {
                SetResourceReferenceToNull(entityResource, navigationProperty);
            }
            else
            {
                PropertyInfo clrProperty = entityResource.GetType().GetProperty(navigationProperty.Name);

                IEdmEntityTypeReference elementType = navigationProperty.Type.AsEntity();
                object childEntityResource          = CreateNestedEntityAndApplyProperties(entry, elementType, readContext);

                clrProperty.SetValue(entityResource, childEntityResource, index: null);
            }
        }
 /// <summary>
 /// Read an <see cref="IODataRequestMessage"/> using messageReader
 /// </summary>
 /// <param name="messageReader">The messageReader to use</param>
 /// <param name="readContext">The read context</param>
 /// <returns></returns>
 public virtual object Read(ODataMessageReader messageReader, ODataDeserializerReadContext readContext)
 {
     throw Error.NotSupported(SRResources.DeserializerDoesNotSupportRead, GetType().Name);
 }
 internal static void RecurseLeave(ODataDeserializerReadContext readContext)
 {
     readContext.DecrementCurrentReferenceDepth();
 }
        private void CreateEntityResource(ODataEntryAnnotation entryAnnotation, IEdmEntityTypeReference entityType, ODataDeserializerReadContext readContext)
        {
            Type clrType = EdmLibHelpers.GetClrType(entityType, EdmModel);

            if (clrType == null)
            {
                throw Error.Argument("entityType", SRResources.MappingDoesNotContainEntityType, entityType.FullName());
            }

            object resource;

            if (!readContext.IsPatchMode)
            {
                resource = Activator.CreateInstance(clrType);
            }
            else
            {
                resource = Activator.CreateInstance(typeof(Delta <>).MakeGenericType(clrType));
            }

            entryAnnotation.EntityResource = resource;
            entryAnnotation.EntityType     = entityType;
        }
 public virtual object ReadInline(object item, ODataDeserializerReadContext readContext)
 {
     throw Error.NotSupported(SRResources.DoesNotSupportReadInLine, GetType().Name);
 }
        private void ApplyEntityProperties(ODataEntry entry, ODataEntryAnnotation entryAnnotation, ODataDeserializerReadContext readContext)
        {
            object entityResource = entryAnnotation.EntityResource;
            IEdmEntityTypeReference entityType = entryAnnotation.EntityType;

            ApplyValueProperties(entry, entityType, entityResource, readContext);
            ApplyNavigationProperties(entryAnnotation, entityType, entityResource, readContext);
        }
        internal static object ConvertValue(object oDataValue, ref IEdmTypeReference propertyType, ODataDeserializerProvider deserializerProvider, ODataDeserializerReadContext readContext)
        {
            if (oDataValue == null)
            {
                return(null);
            }

            ODataComplexValue complexValue = oDataValue as ODataComplexValue;

            if (complexValue != null)
            {
                return(ConvertComplexValue(complexValue, ref propertyType, deserializerProvider, readContext));
            }

            ODataCollectionValue collection = oDataValue as ODataCollectionValue;

            if (collection != null)
            {
                Contract.Assert(propertyType != null, "Open collection properties are not supported.");
                return(ConvertCollectionValue(collection, propertyType, deserializerProvider, readContext));
            }

            return(ConvertPrimitiveValue(oDataValue, ref propertyType));
        }