internal static object CreateResource(IEdmComplexTypeReference complexType, ODataDeserializerContext readContext)
        {
            if (complexType == null)
            {
                throw Error.ArgumentNull("complexType");
            }
            if (readContext == null)
            {
                throw Error.ArgumentNull("readContext");
            }

            IEdmModel model = readContext.Model;
            if (model == null)
            {
                throw Error.Argument("readContext", SRResources.ModelMissingFromReadContext);
            }

            if (readContext.IsUntyped)
            {
                return new EdmComplexObject(complexType);
            }
            else
            {
                Type clrType = EdmLibHelpers.GetClrType(complexType, readContext.Model);
                if (clrType == null)
                {
                    throw Error.InvalidOperation(SRResources.MappingDoesNotContainEntityType, complexType.FullName());
                }

                if (readContext.IsDeltaOfT)
                {
                    Type elementType = readContext.ResourceType.GetGenericArguments()[0];
                    if (elementType != clrType)
                    {
                        // Just create the object for inline complex type
                        return Activator.CreateInstance(clrType);
                    }

                    IEnumerable<string> structuralProperties = complexType.StructuralProperties()
                        .Select(edmProperty => EdmLibHelpers.GetClrPropertyName(edmProperty, model));

                    if (complexType.IsOpen())
                    {
                        PropertyInfo dynamicDictionaryPropertyInfo = EdmLibHelpers.GetDynamicPropertyDictionary(
                            complexType.StructuredDefinition(), model);

                        return Activator.CreateInstance(readContext.ResourceType, clrType, structuralProperties,
                            dynamicDictionaryPropertyInfo);
                    }
                    else
                    {
                        return Activator.CreateInstance(readContext.ResourceType, clrType, structuralProperties);
                    }
                }
                else
                {
                    return Activator.CreateInstance(clrType);
                }
            }
        }
示例#2
0
        internal static object CreateResource(IEdmComplexTypeReference complexType, ODataDeserializerContext readContext)
        {
            if (complexType == null)
            {
                throw Error.ArgumentNull("complexType");
            }
            if (readContext == null)
            {
                throw Error.ArgumentNull("readContext");
            }

            IEdmModel model = readContext.Model;

            if (model == null)
            {
                throw Error.Argument("readContext", SRResources.ModelMissingFromReadContext);
            }

            if (readContext.IsUntyped)
            {
                return(new EdmComplexObject(complexType));
            }
            else
            {
                Type clrType = EdmLibHelpers.GetClrType(complexType, readContext.Model);
                if (clrType == null)
                {
                    throw Error.InvalidOperation(SRResources.MappingDoesNotContainEntityType, complexType.FullName());
                }

                if (readContext.IsDeltaOfT)
                {
                    Type elementType = readContext.ResourceType.GetGenericArguments()[0];
                    if (elementType != clrType)
                    {
                        // Just create the object for inline complex type
                        return(Activator.CreateInstance(clrType));
                    }

                    IEnumerable <string> structuralProperties = complexType.StructuralProperties()
                                                                .Select(edmProperty => EdmLibHelpers.GetClrPropertyName(edmProperty, model));

                    if (complexType.IsOpen())
                    {
                        PropertyInfo dynamicDictionaryPropertyInfo = EdmLibHelpers.GetDynamicPropertyDictionary(
                            complexType.StructuredDefinition(), model);

                        return(Activator.CreateInstance(readContext.ResourceType, clrType, structuralProperties,
                                                        dynamicDictionaryPropertyInfo));
                    }
                    else
                    {
                        return(Activator.CreateInstance(readContext.ResourceType, clrType, structuralProperties));
                    }
                }
                else
                {
                    return(Activator.CreateInstance(clrType));
                }
            }
        }