TypeMapping ImportTypeMapping(TypeModel model, string dataType) {
            if (dataType.Length > 0) {
                if (!model.TypeDesc.IsPrimitive) {
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidDataTypeUsage, dataType, "SoapElementAttribute.DataType"));
                }
                TypeDesc td = typeScope.GetTypeDesc(dataType, XmlSchema.Namespace);
                if (td == null) {
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidXsdDataType, dataType, "SoapElementAttribute.DataType", new XmlQualifiedName(dataType, XmlSchema.Namespace).ToString()));
                }
                if (model.TypeDesc.FullName != td.FullName) {
                    throw new InvalidOperationException(Res.GetString(Res.XmlDataTypeMismatch, dataType, "SoapElementAttribute.DataType", model.TypeDesc.FullName));
                }
            }

            SoapAttributes a = GetAttributes(model.Type);
            
            if ((a.SoapFlags & ~SoapAttributeFlags.Type) != 0)
                throw new InvalidOperationException(Res.GetString(Res.XmlInvalidTypeAttributes, model.Type.FullName));

            switch (model.TypeDesc.Kind) {
                case TypeKind.Enum: 
                    return ImportEnumMapping((EnumModel)model);
                case TypeKind.Primitive:
                    return ImportPrimitiveMapping((PrimitiveModel)model, dataType);
                case TypeKind.Array:
                case TypeKind.Collection:
                case TypeKind.Enumerable:
                    return ImportArrayLikeMapping((ArrayModel)model);
                case TypeKind.Root:
                case TypeKind.Class:
                case TypeKind.Struct:
                    if (model.TypeDesc.IsOptionalValue) {
                        TypeDesc baseTypeDesc = model.TypeDesc.BaseTypeDesc;
                        SoapAttributes baseAttributes = GetAttributes(baseTypeDesc.Type);
                        string typeNs = defaultNs;
                        if (baseAttributes.SoapType != null && baseAttributes.SoapType.Namespace != null)
                            typeNs = baseAttributes.SoapType.Namespace;

                        TypeMapping baseMapping = GetTypeMapping(baseTypeDesc.Name, typeNs, baseTypeDesc);
                        if (baseMapping == null)
                            baseMapping = ImportTypeMapping(modelScope.GetTypeModel(baseTypeDesc.Type, true), dataType);
                        return CreateNullableMapping(baseMapping, model.TypeDesc);
                    }
                    else {
                        return ImportStructLikeMapping((StructModel)model);
                    }
                default:
                    throw new NotSupportedException(Res.GetString(Res.XmlUnsupportedSoapTypeKind, model.TypeDesc.FullName));
            }
        }
Example #2
0
 private TypeMapping ImportTypeMapping(TypeModel model, RecursionLimiter limiter)
 {
     return ImportTypeMapping(model, String.Empty, limiter);
 }
 TypeMapping ImportTypeMapping(TypeModel model) {
     return ImportTypeMapping(model, String.Empty);
 }
 TypeMapping ImportTypeMapping(TypeModel model, string ns, ImportContext context, string dataType, XmlAttributes a) {
     return ImportTypeMapping(model, ns, context, dataType, a, false, false);
 }
        TypeMapping ImportTypeMapping(TypeModel model, string ns, ImportContext context, string dataType, XmlAttributes a, bool repeats, bool openModel) {
            try {
                if (dataType.Length > 0) {
                    TypeDesc modelTypeDesc = TypeScope.IsOptionalValue(model.Type) ? model.TypeDesc.BaseTypeDesc : model.TypeDesc;
                    if (!modelTypeDesc.IsPrimitive) {
                        throw new InvalidOperationException(Res.GetString(Res.XmlInvalidDataTypeUsage, dataType, "XmlElementAttribute.DataType"));
                    }
                    TypeDesc td = typeScope.GetTypeDesc(dataType, XmlSchema.Namespace);
                    if (td == null) {
                        throw new InvalidOperationException(Res.GetString(Res.XmlInvalidXsdDataType, dataType, "XmlElementAttribute.DataType", new XmlQualifiedName(dataType, XmlSchema.Namespace).ToString()));
                    }
                    if (modelTypeDesc.FullName != td.FullName) {
                        throw new InvalidOperationException(Res.GetString(Res.XmlDataTypeMismatch, dataType, "XmlElementAttribute.DataType", modelTypeDesc.FullName));
                    }
                }

                if (a == null)
                    a = GetAttributes(model.Type, false);
                
                if ((a.XmlFlags & ~(XmlAttributeFlags.Type | XmlAttributeFlags.Root)) != 0)
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidTypeAttributes, model.Type.FullName));

                switch (model.TypeDesc.Kind) {
                case TypeKind.Enum: 
                    return ImportEnumMapping((EnumModel)model, ns, repeats);
                case TypeKind.Primitive:
                    if (a.XmlFlags != 0) throw InvalidAttributeUseException(model.Type);
                    return ImportPrimitiveMapping((PrimitiveModel)model, context, dataType, repeats);
                case TypeKind.Array:
                case TypeKind.Collection:
                case TypeKind.Enumerable:
                    //if (a.XmlFlags != 0) throw InvalidAttributeUseException(model.Type);
                    if (context != ImportContext.Element) throw UnsupportedException(model.TypeDesc, context);
                    arrayNestingLevel++;
                    ArrayMapping arrayMapping = ImportArrayLikeMapping((ArrayModel)model, ns);
                    arrayNestingLevel--;
                    return arrayMapping;
                case TypeKind.Root:
                case TypeKind.Class:
                case TypeKind.Struct:
                    if (context != ImportContext.Element) throw UnsupportedException(model.TypeDesc, context);
                    if (model.TypeDesc.IsOptionalValue) {
                        TypeMapping baseMapping = GetTypeMapping(model.TypeDesc.BaseTypeDesc.Name, ns, model.TypeDesc.BaseTypeDesc, types, null);
                        if (baseMapping == null)
                            baseMapping = ImportTypeMapping(modelScope.GetTypeModel(model.TypeDesc.BaseTypeDesc.Type, true), ns, context, dataType, null, repeats, openModel);
                        return CreateNullableMapping(baseMapping, model.TypeDesc);
                    }
                    else {
                        return ImportStructLikeMapping((StructModel)model, ns, openModel, a);
                    }
                default:
                    if (model.TypeDesc.Kind == TypeKind.Serializable) {
                        // We allow XmlRoot attribute on IXmlSerializable, but not others
                        if ((a.XmlFlags & ~XmlAttributeFlags.Root) != 0) {
                            throw new InvalidOperationException(Res.GetString(Res.XmlSerializableAttributes, model.TypeDesc.FullName, typeof(XmlSchemaProviderAttribute).Name));
                        }
                    }
                    else {
                        if (a.XmlFlags != 0) throw InvalidAttributeUseException(model.Type);
                    }
                    if (model.TypeDesc.IsSpecial)
                        return ImportSpecialMapping(model.Type, model.TypeDesc, ns, context);
                    throw UnsupportedException(model.TypeDesc, context);
                }
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                    throw;
                }
                throw CreateTypeReflectionException(model.TypeDesc.FullName, e);
            }
            catch {
                throw CreateTypeReflectionException(model.TypeDesc.FullName, null);
            }
        }
Example #6
0
        TypeMapping ImportTypeMapping(TypeModel model, string ns, ImportContext context, string dataType, XmlSchemaForm form, bool repeats) {
            
            if (dataType.Length > 0) {
                if (!model.TypeDesc.IsPrimitive) {
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidDataTypeUsage, dataType, "XmlElementAttribute.DataType"));
                }
                TypeDesc td = typeScope.GetTypeDesc(new XmlQualifiedName(dataType, XmlSchema.Namespace));
                if (td == null) {
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidXsdDataType, dataType, "XmlElementAttribute.DataType", new XmlQualifiedName(dataType, XmlSchema.Namespace).ToString()));
                }
                if (model.TypeDesc.FullName != td.FullName) {
                    throw new InvalidOperationException(Res.GetString(Res.XmlDataTypeMismatch, dataType, "XmlElementAttribute.DataType", model.TypeDesc.FullName));
                }
            }

            XmlAttributes a = GetAttributes(model.Type);
            
            if ((a.XmlFlags & ~(XmlAttributeFlags.Type | XmlAttributeFlags.Root)) != 0)
                throw new InvalidOperationException(Res.GetString(Res.XmlInvalidTypeAttributes, model.Type.FullName));

            switch (model.TypeDesc.Kind) {
                case TypeKind.Enum: 
                    return ImportEnumMapping((EnumModel)model, ns, repeats);
                case TypeKind.Primitive:
                    if (a.XmlFlags != 0) throw InvalidAttributeUseException(model.Type);
                    return ImportPrimitiveMapping((PrimitiveModel)model, context, dataType, repeats);
                case TypeKind.Array:
                case TypeKind.Collection:
                case TypeKind.Enumerable:
                    if (a.XmlFlags != 0) throw InvalidAttributeUseException(model.Type);
                    if (context != ImportContext.Element) throw UnsupportedException(model.TypeDesc, context);
                    arrayNestingLevel++;
                    ArrayMapping arrayMapping = ImportArrayLikeMapping((ArrayModel)model, ns, form);
                    arrayNestingLevel--;
                    return arrayMapping;
                case TypeKind.Root:
                case TypeKind.Class:
                case TypeKind.Struct:
                case TypeKind.Interface:
                    if (context != ImportContext.Element) throw UnsupportedException(model.TypeDesc, context);
                    return ImportStructLikeMapping((StructModel)model, ns, form);
                default:
                    if (a.XmlFlags != 0) throw InvalidAttributeUseException(model.Type);
                    if (model.TypeDesc.IsSpecial)
                        return ImportSpecialMapping(model.Type, model.TypeDesc, ns, context);
                    throw UnsupportedException(model.TypeDesc, context);
            }
        }
        ElementAccessor ImportElement(TypeModel model, XmlRootAttribute root, string defaultNamespace) {
            XmlAttributes a = GetAttributes(model.Type, true);

            if (root == null)
                root = a.XmlRoot;
            string ns = root == null ? null : root.Namespace;
            if (ns == null && a.XmlRoot == null && a.XmlType != null && a.XmlType.AnonymousType) {
                ns = a.XmlType.Namespace;
            }
            if (ns == null) ns = defaultNamespace;
            if (ns == null) ns = this.defaultNs;

            arrayNestingLevel = -1;
            savedArrayItemAttributes = null;
            savedArrayNamespace = null;
            ElementAccessor element = CreateElementAccessor(ImportTypeMapping(model, ns, ImportContext.Element, string.Empty, a), ns);

            if (root != null) {
                if (root.ElementName.Length > 0)
                    element.Name = XmlConvert.EncodeLocalName(root.ElementName);
                if (root.IsNullableSpecified && !root.IsNullable && model.TypeDesc.IsOptionalValue)
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidNotNullable, model.TypeDesc.BaseTypeDesc.FullName, "XmlRoot"));
                element.IsNullable = root.IsNullableSpecified ? root.IsNullable : model.TypeDesc.IsNullable || model.TypeDesc.IsOptionalValue;
                CheckNullable(element.IsNullable, model.TypeDesc, element.Mapping);
            }
            else
                element.IsNullable = model.TypeDesc.IsNullable || model.TypeDesc.IsOptionalValue;
            element.Form = XmlSchemaForm.Qualified;
            return (ElementAccessor)ReconcileAccessor(element, this.elements);
        }
Example #8
0
        ElementAccessor ImportElement(TypeModel model, XmlRootAttribute root, string defaultNamespace, XmlSchemaForm form) {
            XmlAttributes a = GetAttributes(model.Type);

            if (root == null)
                root = a.XmlRoot;
            string ns = root == null ? null : root.Namespace;
            if (ns == null) ns = defaultNamespace;
            if (ns == null) ns = this.defaultNs;

            arrayNestingLevel = -1;
            savedArrayItemAttributes = null;
            savedArrayNamespace = null;
            ElementAccessor element = CreateElementAccessor(ImportTypeMapping(model, ns, ImportContext.Element, string.Empty, form, false), ns);

            if (root != null) {
                if (root.ElementName.Length > 0)
                    element.Name = Accessor.EscapeName(root.ElementName, false);
                element.IsNullable = root.IsNullableSpecified ? root.IsNullable : model.TypeDesc.IsNullable;
                CheckNullable(element.IsNullable, model.TypeDesc);
            }
            else
                element.IsNullable = model.TypeDesc.IsNullable;
            element.Form = form;
            return ReconcileAccessor(element);
        }
Example #9
0
 TypeMapping ImportTypeMapping(TypeModel model, string ns, ImportContext context, string dataType) {
     return ImportTypeMapping(model, ns, context, dataType, XmlSchemaForm.Qualified, false);
 }
        ElementAccessor ImportElement(TypeModel model, XmlRootAttribute root, string defaultNamespace, RecursionLimiter limiter) {
            XmlAttributes a = GetAttributes(model.Type, true);

            if (root == null)
                root = a.XmlRoot;
            string ns = root == null ? null : root.Namespace;
            if (ns == null) ns = defaultNamespace;
            if (ns == null) ns = this.defaultNs;

            arrayNestingLevel = -1;
            savedArrayItemAttributes = null;
            savedArrayNamespace = null;
            ElementAccessor element = CreateElementAccessor(ImportTypeMapping(model, ns, ImportContext.Element, string.Empty, a, limiter), ns);

            if (root != null) {
                if (root.ElementName.Length > 0)
                    element.Name = XmlConvert.EncodeLocalName(root.ElementName);
                if (root.IsNullableSpecified && !root.IsNullable && model.TypeDesc.IsOptionalValue)
                    //XmlInvalidNotNullable=IsNullable may not be set to 'false' for a Nullable<{0}> type. Consider using '{0}' type or removing the IsNullable property from the XmlElement attribute.
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidNotNullable, model.TypeDesc.BaseTypeDesc.FullName, "XmlRoot"));
                element.IsNullable = root.IsNullableSpecified ? root.IsNullable : model.TypeDesc.IsNullable || model.TypeDesc.IsOptionalValue;
                CheckNullable(element.IsNullable, model.TypeDesc, element.Mapping);
            }
            else
                element.IsNullable = model.TypeDesc.IsNullable || model.TypeDesc.IsOptionalValue;
            element.Form = XmlSchemaForm.Qualified;
            return (ElementAccessor)ReconcileAccessor(element, this.elements);
        }
 TypeMapping ImportTypeMapping(TypeModel model, string ns, ImportContext context, string dataType, XmlAttributes a, RecursionLimiter limiter) {
     return ImportTypeMapping(model, ns, context, dataType, a, false, false, limiter);
 }
        private TypeMapping ImportTypeMapping(TypeModel model, string ns, ImportContext context, string dataType, XmlAttributes a, bool repeats, bool openModel, RecursionLimiter limiter)
        {
            TypeMapping mapping3;
            try
            {
                if (dataType.Length > 0)
                {
                    TypeDesc desc = TypeScope.IsOptionalValue(model.Type) ? model.TypeDesc.BaseTypeDesc : model.TypeDesc;
                    if (!desc.IsPrimitive)
                    {
                        throw new InvalidOperationException(Res.GetString("XmlInvalidDataTypeUsage", new object[] { dataType, "XmlElementAttribute.DataType" }));
                    }
                    TypeDesc typeDesc = this.typeScope.GetTypeDesc(dataType, "http://www.w3.org/2001/XMLSchema");
                    if (typeDesc == null)
                    {
                        throw new InvalidOperationException(Res.GetString("XmlInvalidXsdDataType", new object[] { dataType, "XmlElementAttribute.DataType", new XmlQualifiedName(dataType, "http://www.w3.org/2001/XMLSchema").ToString() }));
                    }
                    if (desc.FullName != typeDesc.FullName)
                    {
                        throw new InvalidOperationException(Res.GetString("XmlDataTypeMismatch", new object[] { dataType, "XmlElementAttribute.DataType", desc.FullName }));
                    }
                }
                if (a == null)
                {
                    a = this.GetAttributes(model.Type, false);
                }
                if ((a.XmlFlags & ~(XmlAttributeFlags.Type | XmlAttributeFlags.Root)) != ((XmlAttributeFlags) 0))
                {
                    throw new InvalidOperationException(Res.GetString("XmlInvalidTypeAttributes", new object[] { model.Type.FullName }));
                }
                switch (model.TypeDesc.Kind)
                {
                    case TypeKind.Root:
                    case TypeKind.Struct:
                    case TypeKind.Class:
                        if (context != ImportContext.Element)
                        {
                            throw UnsupportedException(model.TypeDesc, context);
                        }
                        goto Label_0216;

                    case TypeKind.Primitive:
                        if (a.XmlFlags != ((XmlAttributeFlags) 0))
                        {
                            throw InvalidAttributeUseException(model.Type);
                        }
                        return this.ImportPrimitiveMapping((PrimitiveModel) model, context, dataType, repeats);

                    case TypeKind.Enum:
                        return this.ImportEnumMapping((EnumModel) model, ns, repeats);

                    case TypeKind.Array:
                    case TypeKind.Collection:
                    case TypeKind.Enumerable:
                        if (context != ImportContext.Element)
                        {
                            throw UnsupportedException(model.TypeDesc, context);
                        }
                        break;

                    default:
                        goto Label_02E5;
                }
                this.arrayNestingLevel++;
                ArrayMapping mapping = this.ImportArrayLikeMapping((ArrayModel) model, ns, limiter);
                this.arrayNestingLevel--;
                return mapping;
            Label_0216:
                if (model.TypeDesc.IsOptionalValue)
                {
                    TypeDesc desc3 = string.IsNullOrEmpty(dataType) ? model.TypeDesc.BaseTypeDesc : this.typeScope.GetTypeDesc(dataType, "http://www.w3.org/2001/XMLSchema");
                    string typeName = (desc3.DataType == null) ? desc3.Name : desc3.DataType.Name;
                    TypeMapping baseMapping = this.GetTypeMapping(typeName, ns, desc3, this.types, null);
                    if (baseMapping == null)
                    {
                        baseMapping = this.ImportTypeMapping(this.modelScope.GetTypeModel(model.TypeDesc.BaseTypeDesc.Type), ns, context, dataType, null, repeats, openModel, limiter);
                    }
                    return this.CreateNullableMapping(baseMapping, model.TypeDesc.Type);
                }
                return this.ImportStructLikeMapping((StructModel) model, ns, openModel, a, limiter);
            Label_02E5:
                if (model.TypeDesc.Kind == TypeKind.Serializable)
                {
                    if ((a.XmlFlags & ~XmlAttributeFlags.Root) != ((XmlAttributeFlags) 0))
                    {
                        throw new InvalidOperationException(Res.GetString("XmlSerializableAttributes", new object[] { model.TypeDesc.FullName, typeof(XmlSchemaProviderAttribute).Name }));
                    }
                }
                else if (a.XmlFlags != ((XmlAttributeFlags) 0))
                {
                    throw InvalidAttributeUseException(model.Type);
                }
                if (!model.TypeDesc.IsSpecial)
                {
                    throw UnsupportedException(model.TypeDesc, context);
                }
                mapping3 = this.ImportSpecialMapping(model.Type, model.TypeDesc, ns, context, limiter);
            }
            catch (Exception exception)
            {
                if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                {
                    throw;
                }
                throw this.CreateTypeReflectionException(model.TypeDesc.FullName, exception);
            }
            return mapping3;
        }
 private ElementAccessor ImportElement(TypeModel model, XmlRootAttribute root, string defaultNamespace, RecursionLimiter limiter)
 {
     XmlAttributes a = this.GetAttributes(model.Type, true);
     if (root == null)
     {
         root = a.XmlRoot;
     }
     string ns = (root == null) ? null : root.Namespace;
     if (ns == null)
     {
         ns = defaultNamespace;
     }
     if (ns == null)
     {
         ns = this.defaultNs;
     }
     this.arrayNestingLevel = -1;
     this.savedArrayItemAttributes = null;
     this.savedArrayNamespace = null;
     ElementAccessor accessor = CreateElementAccessor(this.ImportTypeMapping(model, ns, ImportContext.Element, string.Empty, a, limiter), ns);
     if (root != null)
     {
         if (root.ElementName.Length > 0)
         {
             accessor.Name = XmlConvert.EncodeLocalName(root.ElementName);
         }
         if ((root.IsNullableSpecified && !root.IsNullable) && model.TypeDesc.IsOptionalValue)
         {
             throw new InvalidOperationException(Res.GetString("XmlInvalidNotNullable", new object[] { model.TypeDesc.BaseTypeDesc.FullName, "XmlRoot" }));
         }
         accessor.IsNullable = root.IsNullableSpecified ? root.IsNullable : (model.TypeDesc.IsNullable || model.TypeDesc.IsOptionalValue);
         CheckNullable(accessor.IsNullable, model.TypeDesc, accessor.Mapping);
     }
     else
     {
         accessor.IsNullable = model.TypeDesc.IsNullable || model.TypeDesc.IsOptionalValue;
     }
     accessor.Form = XmlSchemaForm.Qualified;
     return (ElementAccessor) this.ReconcileAccessor(accessor, this.elements);
 }
        private TypeMapping ImportTypeMapping(TypeModel model, string dataType, RecursionLimiter limiter)
        {
            if (dataType.Length > 0)
            {
                if (!model.TypeDesc.IsPrimitive)
                {
                    throw new InvalidOperationException(SR.Format(SR.XmlInvalidDataTypeUsage, dataType, "SoapElementAttribute.DataType"));
                }
                TypeDesc td = _typeScope.GetTypeDesc(dataType, XmlSchema.Namespace);
                if (td == null)
                {
                    throw new InvalidOperationException(SR.Format(SR.XmlInvalidXsdDataType, dataType, "SoapElementAttribute.DataType", new XmlQualifiedName(dataType, XmlSchema.Namespace).ToString()));
                }
                if (model.TypeDesc.FullName != td.FullName)
                {
                    throw new InvalidOperationException(SR.Format(SR.XmlDataTypeMismatch, dataType, "SoapElementAttribute.DataType", model.TypeDesc.FullName));
                }
            }

            SoapAttributes a = GetAttributes(model.Type);

            if ((a.GetSoapFlags() & ~SoapAttributeFlags.Type) != 0)
            {
                throw new InvalidOperationException(SR.Format(SR.XmlInvalidTypeAttributes, model.Type.FullName));
            }

            switch (model.TypeDesc.Kind)
            {
            case TypeKind.Enum:
                return(ImportEnumMapping((EnumModel)model));

            case TypeKind.Primitive:
                return(ImportPrimitiveMapping((PrimitiveModel)model, dataType));

            case TypeKind.Array:
            case TypeKind.Collection:
            case TypeKind.Enumerable:
                return(ImportArrayLikeMapping((ArrayModel)model, limiter));

            case TypeKind.Root:
            case TypeKind.Class:
            case TypeKind.Struct:
                if (model.TypeDesc.IsOptionalValue)
                {
                    TypeDesc       baseTypeDesc   = model.TypeDesc.BaseTypeDesc;
                    SoapAttributes baseAttributes = GetAttributes(baseTypeDesc.Type);
                    string         typeNs         = _defaultNs;
                    if (baseAttributes.SoapType != null && baseAttributes.SoapType.Namespace != null)
                    {
                        typeNs = baseAttributes.SoapType.Namespace;
                    }
                    TypeDesc    valueTypeDesc = string.IsNullOrEmpty(dataType) ? model.TypeDesc.BaseTypeDesc : _typeScope.GetTypeDesc(dataType, XmlSchema.Namespace);
                    string      xsdTypeName   = string.IsNullOrEmpty(dataType) ? model.TypeDesc.BaseTypeDesc.Name : dataType;
                    TypeMapping baseMapping   = GetTypeMapping(xsdTypeName, typeNs, valueTypeDesc);
                    if (baseMapping == null)
                    {
                        baseMapping = ImportTypeMapping(_modelScope.GetTypeModel(baseTypeDesc.Type), dataType, limiter);
                    }
                    return(CreateNullableMapping(baseMapping, model.TypeDesc.Type));
                }
                else
                {
                    return(ImportStructLikeMapping((StructModel)model, limiter));
                }

            default:
                throw new NotSupportedException(SR.Format(SR.XmlUnsupportedSoapTypeKind, model.TypeDesc.FullName));
            }
        }
 private TypeMapping ImportTypeMapping(TypeModel model, RecursionLimiter limiter)
 {
     return(ImportTypeMapping(model, string.Empty, limiter));
 }
Example #16
0
        TypeMapping ImportTypeMapping(TypeModel model, string dataType) {
            if (dataType.Length > 0) {
                if (!model.TypeDesc.IsPrimitive) {
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidDataTypeUsage, dataType, "SoapElementAttribute.DataType"));
                }
                TypeDesc td = typeScope.GetTypeDesc(new XmlQualifiedName(dataType, XmlSchema.Namespace));
                if (td == null) {
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidXsdDataType, dataType, "SoapElementAttribute.DataType", new XmlQualifiedName(dataType, XmlSchema.Namespace).ToString()));
                }
                if (model.TypeDesc.FullName != td.FullName) {
                    throw new InvalidOperationException(Res.GetString(Res.XmlDataTypeMismatch, dataType, "SoapElementAttribute.DataType", model.TypeDesc.FullName));
                }
            }

            SoapAttributes a = GetAttributes(model.Type);
            
            if ((a.SoapFlags & ~SoapAttributeFlags.Type) != 0)
                throw new InvalidOperationException(Res.GetString(Res.XmlInvalidTypeAttributes, model.Type.FullName));

            switch (model.TypeDesc.Kind) {
                case TypeKind.Enum: 
                    return ImportEnumMapping((EnumModel)model);
                case TypeKind.Primitive:
                    return ImportPrimitiveMapping((PrimitiveModel)model, dataType);
                case TypeKind.Array:
                case TypeKind.Collection:
                case TypeKind.Enumerable:
                    return ImportArrayLikeMapping((ArrayModel)model);
                case TypeKind.Root:
                case TypeKind.Class:
                case TypeKind.Struct:
                case TypeKind.Interface:
                    return ImportStructLikeMapping((StructModel)model);
                default:
                    throw new NotSupportedException(Res.GetString(Res.XmlUnsupportedSoapTypeKind, model.TypeDesc.FullName));
            }
        }