Exemplo n.º 1
0
        private MemberMapping[] ImportTypeMembers(XmlSchemaComplexType type, string typeNs, CodeIdentifiers members)
        {
            if (type.AnyAttribute != null)
            {
                throw new InvalidOperationException(string.Format(ResXml.XmlInvalidAnyAttributeUse, type.Name, type.QualifiedName.Namespace));
            }

            XmlSchemaObjectCollection items = type.Attributes;

            for (int i = 0; i < items.Count; i++)
            {
                object item = items[i];
                if (item is XmlSchemaAttributeGroup)
                {
                    throw new InvalidOperationException(string.Format(ResXml.XmlSoapInvalidAttributeUse, type.Name, type.QualifiedName.Namespace));
                }
                if (item is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)item;
                    if (attr.Use != XmlSchemaUse.Prohibited)
                    {
                        throw new InvalidOperationException(string.Format(ResXml.XmlSoapInvalidAttributeUse, type.Name, type.QualifiedName.Namespace));
                    }
                }
            }
            if (type.Particle != null)
            {
                ImportGroup(type.Particle, members, typeNs);
            }
            else if (type.ContentModel != null && type.ContentModel is XmlSchemaComplexContent)
            {
                XmlSchemaComplexContent model = (XmlSchemaComplexContent)type.ContentModel;

                if (model.Content is XmlSchemaComplexContentExtension)
                {
                    if (((XmlSchemaComplexContentExtension)model.Content).Particle != null)
                    {
                        ImportGroup(((XmlSchemaComplexContentExtension)model.Content).Particle, members, typeNs);
                    }
                }
                else if (model.Content is XmlSchemaComplexContentRestriction)
                {
                    if (((XmlSchemaComplexContentRestriction)model.Content).Particle != null)
                    {
                        ImportGroup(((XmlSchemaComplexContentRestriction)model.Content).Particle, members, typeNs);
                    }
                }
            }
            return((MemberMapping[])members.ToArray(typeof(MemberMapping)));
        }
Exemplo n.º 2
0
        private TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, bool isList)
        {
            TypeMapping mapping = (TypeMapping)ImportedMappings[dataType];

            if (mapping != null)
            {
                return(mapping);
            }

            XmlSchemaSimpleType sourceDataType = FindDataType(dataType.DerivedFrom);
            TypeDesc            sourceTypeDesc = Scope.GetTypeDesc(sourceDataType);

            if (sourceTypeDesc != null && sourceTypeDesc != Scope.GetTypeDesc(typeof(string)))
            {
                return(ImportPrimitiveDataType(dataType));
            }
            identifier = Accessor.UnescapeName(identifier);
            string      typeName    = GenerateUniqueTypeName(identifier);
            EnumMapping enumMapping = new EnumMapping();

            enumMapping.IsReference = Schemas.IsReference(dataType);
            enumMapping.TypeDesc    = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0);
            enumMapping.TypeName    = identifier;
            enumMapping.Namespace   = typeNs;
            enumMapping.IsFlags     = isList;
            CodeIdentifiers constants = new CodeIdentifiers();

            if (!(dataType.Content is XmlSchemaSimpleTypeRestriction))
            {
                throw new InvalidOperationException(string.Format(ResXml.XmlInvalidEnumContent, dataType.Content.GetType().Name, identifier));
            }

            XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)dataType.Content;

            for (int i = 0; i < restriction.Facets.Count; i++)
            {
                object facet = restriction.Facets[i];
                if (!(facet is XmlSchemaEnumerationFacet))
                {
                    continue;
                }
                XmlSchemaEnumerationFacet enumeration = (XmlSchemaEnumerationFacet)facet;
                ConstantMapping           constant    = new ConstantMapping();
                string constantName = CodeIdentifier.MakeValid(enumeration.Value);
                constant.Name    = constants.AddUnique(constantName, constant);
                constant.XmlName = enumeration.Value;
                constant.Value   = i;
            }
            enumMapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping));
            if (isList && enumMapping.Constants.Length > 63)
            {
                // if we have 64+ flag constants we cannot map the type to long enum, we will use string mapping instead.
                mapping          = new PrimitiveMapping();
                mapping.TypeDesc = Scope.GetTypeDesc(typeof(string));
                mapping.TypeName = mapping.TypeDesc.DataType.Name;
                ImportedMappings.Add(dataType, mapping);
                return(mapping);
            }
            ImportedMappings.Add(dataType, enumMapping);
            Scope.AddTypeMapping(enumMapping);
            return(enumMapping);
        }