Esempio n. 1
0
        private void ApplyResourceSetInNestedProperty(IEdmProperty nestedProperty, object resource,
                                                      ODataResourceSetWrapper resourceSetWrapper, ODataDeserializerContext readContext)
        {
            Contract.Assert(nestedProperty != null);
            Contract.Assert(resource != null);
            Contract.Assert(readContext != null);

            object value = ReadNestedResourceSetInline(resourceSetWrapper, nestedProperty.Type, readContext);

            string propertyName = readContext.Model.GetClrPropertyName(nestedProperty);

            DeserializationHelpers.SetCollectionProperty(resource, nestedProperty, value, propertyName);
        }
Esempio n. 2
0
        private void ApplyDynamicResourceInNestedProperty(string propertyName, object resource, IEdmStructuredTypeReference resourceStructuredType,
                                                          ODataResourceWrapper resourceWrapper, ODataDeserializerContext readContext)
        {
            Contract.Assert(resource != null);
            Contract.Assert(readContext != null);

            IEdmSchemaType    elementType      = readContext.Model.FindDeclaredType(resourceWrapper.Resource.TypeName);
            IEdmTypeReference edmTypeReference = elementType.ToEdmTypeReference(true);

            object value = ReadNestedResourceInline(resourceWrapper, edmTypeReference, readContext);

            DeserializationHelpers.SetDynamicProperty(resource, propertyName, value,
                                                      resourceStructuredType.StructuredDefinition(), readContext.Model);
        }
Esempio n. 3
0
        private void ApplyResourceInNestedProperty(IEdmProperty nestedProperty, object resource,
                                                   ODataResourceWrapper resourceWrapper, ODataDeserializerContext readContext)
        {
            Contract.Assert(nestedProperty != null);
            Contract.Assert(resource != null);
            Contract.Assert(readContext != null);

            object value = ReadNestedResourceInline(resourceWrapper, nestedProperty.Type, readContext);

            // First resolve Data member alias or annotation, then set the regular
            // or delta resource accordingly.
            string propertyName = readContext.Model.GetClrPropertyName(nestedProperty);

            DeserializationHelpers.SetProperty(resource, propertyName, value);
        }
Esempio n. 4
0
        /// <summary>
        /// Deserializes the given <paramref name="structuralProperty"/> into <paramref name="resource"/>.
        /// </summary>
        /// <param name="resource">The object into which the structural property should be read.</param>
        /// <param name="structuralProperty">The structural property.</param>
        /// <param name="structuredType">The type of the resource.</param>
        /// <param name="readContext">The deserializer context.</param>
        public virtual void ApplyStructuralProperty(object resource, ODataProperty structuralProperty,
                                                    IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)
        {
            if (resource == null)
            {
                throw Error.ArgumentNull("resource");
            }

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

            DeserializationHelpers.ApplyProperty(structuralProperty, structuredType, resource, DeserializerProvider, readContext);
        }
Esempio n. 5
0
        private void ApplyDynamicResourceSetInNestedProperty(string propertyName, object resource, IEdmStructuredTypeReference structuredType,
                                                             ODataResourceSetWrapper resourceSetWrapper, ODataDeserializerContext readContext)
        {
            Contract.Assert(resource != null);
            Contract.Assert(readContext != null);

            if (String.IsNullOrEmpty(resourceSetWrapper.ResourceSet.TypeName))
            {
                //string message = Error.Format(SRResources.DynamicResourceSetTypeNameIsRequired, propertyName);
                throw new ODataException("TODO: ");
            }

            string elementTypeName =
                DeserializationHelpers.GetCollectionElementTypeName(resourceSetWrapper.ResourceSet.TypeName,
                                                                    isNested: false);
            IEdmSchemaType elementType = readContext.Model.FindDeclaredType(elementTypeName);

            IEdmTypeReference          edmTypeReference = elementType.ToEdmTypeReference(true);
            EdmCollectionTypeReference collectionType   = new EdmCollectionTypeReference(new EdmCollectionType(edmTypeReference));

            ODataEdmTypeDeserializer deserializer = DeserializerProvider.GetEdmTypeDeserializer(collectionType);

            if (deserializer == null)
            {
                throw new SerializationException(Error.Format(SRResources.TypeCannotBeDeserialized,
                                                              collectionType.FullName(), typeof(ODataInputFormatter)));
            }

            IEnumerable value  = ReadNestedResourceSetInline(resourceSetWrapper, collectionType, readContext) as IEnumerable;
            object      result = value;

            if (value != null)
            {
                if (readContext.IsUntyped)
                {
                    result = value.ConvertToEdmObject(collectionType);
                }
            }

            DeserializationHelpers.SetDynamicProperty(resource, structuredType, EdmTypeKind.Collection, propertyName,
                                                      result, collectionType, readContext.Model);
        }
Esempio n. 6
0
        private void ApplyNestedDeltaResourceSet(IEdmProperty nestedProperty, object resource,
                                                 ODataDeltaResourceSetWrapper deltaResourceSetWrapper, ODataDeserializerContext readContext)
        {
            Contract.Assert(nestedProperty != null);
            Contract.Assert(resource != null);
            Contract.Assert(readContext != null);

            IEdmTypeReference        edmType      = nestedProperty.Type;
            ODataEdmTypeDeserializer deserializer = DeserializerProvider.GetEdmTypeDeserializer(edmType, true);

            if (deserializer == null)
            {
                throw new SerializationException(Error.Format(SRResources.TypeCannotBeDeserialized, edmType.FullName()));
            }

            IEdmStructuredTypeReference structuredType    = edmType.AsCollection().ElementType().AsStructured();
            ODataDeserializerContext    nestedReadContext = readContext.CloneWithoutType();

            if (readContext.IsNoClrType)
            {
                nestedReadContext.ResourceType = typeof(EdmChangedObjectCollection);
            }
            else
            {
                Type clrType = readContext.Model.GetClrType(structuredType);

                if (clrType == null)
                {
                    throw new ODataException(
                              Error.Format(SRResources.MappingDoesNotContainResourceType, structuredType.FullName()));
                }

                nestedReadContext.ResourceType = typeof(DeltaSet <>).MakeGenericType(clrType);
            }

            object value = deserializer.ReadInline(deltaResourceSetWrapper, edmType, nestedReadContext);

            string propertyName = readContext.Model.GetClrPropertyName(nestedProperty);

            DeserializationHelpers.SetCollectionProperty(resource, nestedProperty, value, propertyName);
        }
Esempio n. 7
0
        private void ApplyResourceSetInNestedProperty(IEdmProperty nestedProperty, object resource,
                                                      ODataResourceSetWrapper resourceSetWrapper, ODataDeserializerContext readContext)
        {
            Contract.Assert(nestedProperty != null);
            Contract.Assert(resource != null);
            Contract.Assert(readContext != null);

            if (readContext.IsDeltaOfT)
            {
                IEdmNavigationProperty navigationProperty = nestedProperty as IEdmNavigationProperty;
                if (navigationProperty != null)
                {
                    string message = Error.Format(SRResources.CannotPatchNavigationProperties, navigationProperty.Name,
                                                  navigationProperty.DeclaringEntityType().FullName());
                    throw new ODataException(message);
                }
            }

            object value = ReadNestedResourceSetInline(resourceSetWrapper, nestedProperty.Type, readContext);

            string propertyName = readContext.Model.GetClrPropertyName(nestedProperty);

            DeserializationHelpers.SetCollectionProperty(resource, nestedProperty, value, propertyName);
        }