ToArray() public méthode

public ToArray ( Type type ) : object
type System.Type
Résultat object
Exemple #1
0
        private TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, bool isList)
        {
            TypeMapping mapping = (TypeMapping)base.ImportedMappings[dataType];

            if (mapping != null)
            {
                return(mapping);
            }
            XmlSchemaSimpleType type     = this.FindDataType(dataType.DerivedFrom);
            TypeDesc            typeDesc = base.Scope.GetTypeDesc(type);

            if ((typeDesc != null) && (typeDesc != base.Scope.GetTypeDesc(typeof(string))))
            {
                return(this.ImportPrimitiveDataType(dataType));
            }
            identifier = Accessor.UnescapeName(identifier);
            string      name     = base.GenerateUniqueTypeName(identifier);
            EnumMapping mapping2 = new EnumMapping {
                IsReference = base.Schemas.IsReference(dataType),
                TypeDesc    = new TypeDesc(name, name, TypeKind.Enum, null, TypeFlags.None),
                TypeName    = identifier,
                Namespace   = typeNs,
                IsFlags     = isList
            };
            CodeIdentifiers identifiers = new CodeIdentifiers();

            if (!(dataType.Content is XmlSchemaSimpleTypeRestriction))
            {
                throw new InvalidOperationException(Res.GetString("XmlInvalidEnumContent", new object[] { dataType.Content.GetType().Name, identifier }));
            }
            XmlSchemaSimpleTypeRestriction content = (XmlSchemaSimpleTypeRestriction)dataType.Content;

            for (int i = 0; i < content.Facets.Count; i++)
            {
                object obj2 = content.Facets[i];
                if (obj2 is XmlSchemaEnumerationFacet)
                {
                    XmlSchemaEnumerationFacet facet    = (XmlSchemaEnumerationFacet)obj2;
                    ConstantMapping           mapping3 = new ConstantMapping();
                    string str2 = CodeIdentifier.MakeValid(facet.Value);
                    mapping3.Name    = identifiers.AddUnique(str2, mapping3);
                    mapping3.XmlName = facet.Value;
                    mapping3.Value   = i;
                }
            }
            mapping2.Constants = (ConstantMapping[])identifiers.ToArray(typeof(ConstantMapping));
            if (isList && (mapping2.Constants.Length > 0x3f))
            {
                mapping = new PrimitiveMapping {
                    TypeDesc = base.Scope.GetTypeDesc(typeof(string)),
                    TypeName = mapping.TypeDesc.DataType.Name
                };
                base.ImportedMappings.Add(dataType, mapping);
                return(mapping);
            }
            base.ImportedMappings.Add(dataType, mapping2);
            base.Scope.AddTypeMapping(mapping2);
            return(mapping2);
        }
        TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier)
        {
            EnumMapping enumMapping = (EnumMapping)mappings[dataType];

            if (enumMapping != null)
            {
                return(enumMapping);
            }
            XmlSchemaSimpleType sourceDataType = FindDataType(dataType.DerivedFrom);
            TypeDesc            sourceTypeDesc = scope.GetTypeDesc(sourceDataType);

            if (sourceTypeDesc != null && sourceTypeDesc != scope.GetTypeDesc(typeof(string)))
            {
                return(ImportPrimitiveDataType(dataType));
            }
            string typeName = GenerateUniqueTypeName(identifier);

            enumMapping           = new EnumMapping();
            enumMapping.TypeDesc  = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0);
            enumMapping.TypeName  = identifier;
            enumMapping.Namespace = typeNs;
            enumMapping.IsFlags   = false;
            mappings.Add(dataType, enumMapping);
            CodeIdentifiers constants = new CodeIdentifiers();

            if (!(dataType.Content is XmlSchemaSimpleTypeRestriction))
            {
                throw new InvalidOperationException(Res.GetString(Res.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));
            scope.AddTypeMapping(enumMapping);
            return(enumMapping);
        }
Exemple #3
0
        private MemberMapping[] ImportTypeMembers(XmlSchemaComplexType type, string typeNs, CodeIdentifiers members)
        {
            if (type.AnyAttribute != null)
            {
                throw new InvalidOperationException(SR.Format(SR.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(SR.Format(SR.XmlSoapInvalidAttributeUse, type.Name, type.QualifiedName.Namespace));
                }
                if (item is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)item;
                    if (attr.Use != XmlSchemaUse.Prohibited)
                    {
                        throw new InvalidOperationException(SR.Format(SR.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)));
        }
Exemple #4
0
        private MemberMapping[] ImportTypeMembers(XmlSchemaComplexType type, string typeNs, CodeIdentifiers members)
        {
            if (type.AnyAttribute != null)
            {
                throw new InvalidOperationException(Res.GetString("XmlInvalidAnyAttributeUse", new object[] { type.Name, type.QualifiedName.Namespace }));
            }
            XmlSchemaObjectCollection attributes = type.Attributes;

            for (int i = 0; i < attributes.Count; i++)
            {
                object obj2 = attributes[i];
                if (obj2 is XmlSchemaAttributeGroup)
                {
                    throw new InvalidOperationException(Res.GetString("XmlSoapInvalidAttributeUse", new object[] { type.Name, type.QualifiedName.Namespace }));
                }
                if (obj2 is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attribute = (XmlSchemaAttribute)obj2;
                    if (attribute.Use != XmlSchemaUse.Prohibited)
                    {
                        throw new InvalidOperationException(Res.GetString("XmlSoapInvalidAttributeUse", new object[] { type.Name, type.QualifiedName.Namespace }));
                    }
                }
            }
            if (type.Particle != null)
            {
                this.ImportGroup(type.Particle, members, typeNs);
            }
            else if ((type.ContentModel != null) && (type.ContentModel is XmlSchemaComplexContent))
            {
                XmlSchemaComplexContent contentModel = (XmlSchemaComplexContent)type.ContentModel;
                if (contentModel.Content is XmlSchemaComplexContentExtension)
                {
                    if (((XmlSchemaComplexContentExtension)contentModel.Content).Particle != null)
                    {
                        this.ImportGroup(((XmlSchemaComplexContentExtension)contentModel.Content).Particle, members, typeNs);
                    }
                }
                else if ((contentModel.Content is XmlSchemaComplexContentRestriction) && (((XmlSchemaComplexContentRestriction)contentModel.Content).Particle != null))
                {
                    this.ImportGroup(((XmlSchemaComplexContentRestriction)contentModel.Content).Particle, members, typeNs);
                }
            }
            return((MemberMapping[])members.ToArray(typeof(MemberMapping)));
        }
Exemple #5
0
        MemberMapping[] ImportTypeMembers(XmlSchemaType type, string typeNs, string identifier, CodeIdentifiers members) {
            TypeItems items = GetTypeItems(type);
            bool mixed = IsMixed(type);

            if (mixed) {
                // check if we can transfer the attribute to the base class
                XmlSchemaType t = type;
                while (!t.DerivedFrom.IsEmpty) {
                    t = FindType(t.DerivedFrom);
                    if (IsMixed(t)) {
                        // keep the mixed attribute on the base class
                        mixed = false;
                        break;
                    }
                }
            }

            if (items.Particle != null) {
                ImportGroup(items.Particle, identifier, members, typeNs, mixed);
            }
            for (int i = 0; i < items.Attributes.Count; i++) {
                object item = items.Attributes[i];
                if (item is XmlSchemaAttribute) {
                    ImportAttributeMember((XmlSchemaAttribute)item, identifier, members, typeNs);
                }
                else if (item is XmlSchemaAttributeGroupRef) {
                    ImportAttributeGroupMembers(FindAttributeGroup(((XmlSchemaAttributeGroupRef)item).RefName), identifier, members, typeNs);
                }
            }
            if (items.baseSimpleType != null) {
                mixed = true;
            }
            if (items.AnyAttribute != null) {
                ImportAnyAttributeMember(items.AnyAttribute, members);
            }
            else if (mixed && items.Particle == null) {
                ImportTextMember(members, items.baseSimpleType);
            }

            ImportXmlnsDeclarationsMember(type, members);
            return (MemberMapping[])members.ToArray(typeof(MemberMapping));
        }
Exemple #6
0
 StructMapping ImportStructDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, Type baseType) {
     string typeName = GenerateUniqueTypeName(identifier);
     StructMapping structMapping = new StructMapping();
     TypeFlags flags = TypeFlags.Reference;
     TypeDesc baseTypeDesc = scope.GetTypeDesc(baseType);
     structMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Struct, baseTypeDesc, flags);
     structMapping.Namespace = typeNs;
     structMapping.TypeName = identifier;
     CodeIdentifiers members = new CodeIdentifiers();
     members.AddReserved(typeName);
     ImportTextMember(members, null);
     structMapping.Members = (MemberMapping[])members.ToArray(typeof(MemberMapping));
     scope.AddTypeMapping(structMapping);
     return structMapping;
 }
Exemple #7
0
        EnumMapping ImportEnumeratedChoice(ElementAccessor[] choice, string typeNs, string typeName) {
            typeName = GenerateUniqueTypeName(typeName, typeNs);
            EnumMapping enumMapping = new EnumMapping();
            enumMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0);
            enumMapping.TypeName = typeName;
            enumMapping.Namespace = typeNs;
            enumMapping.IsFlags = false;
            enumMapping.IncludeInSchema = false;

            CodeIdentifiers constants = new CodeIdentifiers();

            for (int i = 0; i < choice.Length; i++) {
                ElementAccessor element = choice[i];
                ConstantMapping constant = new ConstantMapping();
                string constantName = CodeIdentifier.MakeValid(element.Name);
                constant.Name = constants.AddUnique(constantName, constant);
                constant.XmlName = element.Namespace == typeNs ? element.Name : element.Namespace + ":" + element.Name;
                constant.Value = i;
            }
            enumMapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping));
            scope.AddTypeMapping(enumMapping);
            return enumMapping;
        }
Exemple #8
0
        TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier) {
            EnumMapping enumMapping = (EnumMapping)mappings[dataType];
            if (enumMapping != null) return enumMapping;
            XmlSchemaType sourceType = FindType(dataType.DerivedFrom);
            if (sourceType is XmlSchemaComplexType) return null;
            TypeDesc sourceTypeDesc = scope.GetTypeDesc((XmlSchemaSimpleType)sourceType);
            if (sourceTypeDesc != null && sourceTypeDesc.FullName != typeof(string).FullName)
                return ImportPrimitiveDataType(dataType);
            string typeName = GenerateUniqueTypeName(identifier);
            enumMapping = new EnumMapping();
            enumMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0);
            enumMapping.TypeName = identifier;
            enumMapping.Namespace = typeNs;
            enumMapping.IsFlags = false;

            mappings.Add(dataType, enumMapping);
            CodeIdentifiers constants = new CodeIdentifiers();
            XmlSchemaSimpleTypeContent content = dataType.Content;

            if (content is XmlSchemaSimpleTypeRestriction) {
                XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)content;
                for (int i = 0; i < restriction.Facets.Count; i++) {
                    object facet = restriction.Facets[i];
                    if (!(facet is XmlSchemaEnumerationFacet)) continue;
                    XmlSchemaEnumerationFacet enumeration = (XmlSchemaEnumerationFacet)facet;
                    // validate the enumeration value
                    if (sourceTypeDesc != null && sourceTypeDesc.HasCustomFormatter) {
                        XmlCustomFormatter.ToDefaultValue(enumeration.Value, sourceTypeDesc.FormatterName);
                    }
                    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));
            scope.AddTypeMapping(enumMapping);
            return enumMapping;
        }
        private MemberMapping[] ImportTypeMembers(XmlSchemaType type, string typeNs, string identifier, CodeIdentifiers members, CodeIdentifiers membersScope, INameScope elementsScope, ref bool needExplicitOrder, bool order, bool allowUnboundedElements)
        {
            TypeItems items = GetTypeItems(type);
            bool mixed = IsMixed(type);

            if (mixed)
            {
                // check if we can transfer the attribute to the base class
                XmlSchemaType t = type;
                while (!t.DerivedFrom.IsEmpty)
                {
                    t = FindType(t.DerivedFrom, TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue);
                    if (IsMixed(t))
                    {
                        // keep the mixed attribute on the base class
                        mixed = false;
                        break;
                    }
                }
            }

            if (items.Particle != null)
            {
                ImportGroup(items.Particle, identifier, members, membersScope, elementsScope, typeNs, mixed, ref needExplicitOrder, order, items.IsUnbounded, allowUnboundedElements);
            }
            for (int i = 0; i < items.Attributes.Count; i++)
            {
                object item = items.Attributes[i];
                if (item is XmlSchemaAttribute)
                {
                    ImportAttributeMember((XmlSchemaAttribute)item, identifier, members, membersScope, typeNs);
                }
                else if (item is XmlSchemaAttributeGroupRef)
                {
                    XmlQualifiedName groupName = ((XmlSchemaAttributeGroupRef)item).RefName;
                    ImportAttributeGroupMembers(FindAttributeGroup(groupName), identifier, members, membersScope, groupName.Namespace);
                }
            }
            if (items.AnyAttribute != null)
            {
                ImportAnyAttributeMember(items.AnyAttribute, members, membersScope);
            }

            if (items.baseSimpleType != null || (items.Particle == null && mixed))
            {
                ImportTextMember(members, membersScope, mixed ? null : items.baseSimpleType);
            }

            ImportXmlnsDeclarationsMember(type, members, membersScope);
            MemberMapping[] typeMembers = (MemberMapping[])members.ToArray(typeof(MemberMapping));
            return typeMembers;
        }
 private MemberMapping[] ImportTypeMembers(XmlSchemaComplexType type, string typeNs, CodeIdentifiers members)
 {
     if (type.AnyAttribute != null)
     {
         throw new InvalidOperationException(Res.GetString("XmlInvalidAnyAttributeUse", new object[] { type.Name, type.QualifiedName.Namespace }));
     }
     XmlSchemaObjectCollection attributes = type.Attributes;
     for (int i = 0; i < attributes.Count; i++)
     {
         object obj2 = attributes[i];
         if (obj2 is XmlSchemaAttributeGroup)
         {
             throw new InvalidOperationException(Res.GetString("XmlSoapInvalidAttributeUse", new object[] { type.Name, type.QualifiedName.Namespace }));
         }
         if (obj2 is XmlSchemaAttribute)
         {
             XmlSchemaAttribute attribute = (XmlSchemaAttribute) obj2;
             if (attribute.Use != XmlSchemaUse.Prohibited)
             {
                 throw new InvalidOperationException(Res.GetString("XmlSoapInvalidAttributeUse", new object[] { type.Name, type.QualifiedName.Namespace }));
             }
         }
     }
     if (type.Particle != null)
     {
         this.ImportGroup(type.Particle, members, typeNs);
     }
     else if ((type.ContentModel != null) && (type.ContentModel is XmlSchemaComplexContent))
     {
         XmlSchemaComplexContent contentModel = (XmlSchemaComplexContent) type.ContentModel;
         if (contentModel.Content is XmlSchemaComplexContentExtension)
         {
             if (((XmlSchemaComplexContentExtension) contentModel.Content).Particle != null)
             {
                 this.ImportGroup(((XmlSchemaComplexContentExtension) contentModel.Content).Particle, members, typeNs);
             }
         }
         else if ((contentModel.Content is XmlSchemaComplexContentRestriction) && (((XmlSchemaComplexContentRestriction) contentModel.Content).Particle != null))
         {
             this.ImportGroup(((XmlSchemaComplexContentRestriction) contentModel.Content).Particle, members, typeNs);
         }
     }
     return (MemberMapping[]) members.ToArray(typeof(MemberMapping));
 }
        MemberMapping[] ImportTypeMembers(XmlSchemaComplexType type, string typeNs, CodeIdentifiers members) {
            if (type.AnyAttribute != null) {
                throw new InvalidOperationException(Res.GetString(Res.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(Res.GetString(Res.XmlSoapInvalidAttributeUse, type.Name, type.QualifiedName.Namespace));
                }
                if (item is XmlSchemaAttribute) {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)item;
                    if (attr.Use != XmlSchemaUse.Prohibited) throw new InvalidOperationException(Res.GetString(Res.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));
        }
 private StructMapping ImportStructDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, Type baseType)
 {
     identifier = Accessor.UnescapeName(identifier);
     string name = base.GenerateUniqueTypeName(identifier);
     StructMapping typeMapping = new StructMapping {
         IsReference = base.Schemas.IsReference(dataType)
     };
     TypeFlags reference = TypeFlags.Reference;
     TypeDesc typeDesc = base.Scope.GetTypeDesc(baseType);
     typeMapping.TypeDesc = new TypeDesc(name, name, TypeKind.Struct, typeDesc, reference);
     typeMapping.Namespace = typeNs;
     typeMapping.TypeName = identifier;
     CodeIdentifiers scope = new CodeIdentifiers();
     scope.AddReserved(name);
     base.AddReservedIdentifiersForDataBinding(scope);
     this.ImportTextMember(scope, new CodeIdentifiers(), null);
     typeMapping.Members = (MemberMapping[]) scope.ToArray(typeof(MemberMapping));
     typeMapping.Scope = scope;
     base.Scope.AddTypeMapping(typeMapping);
     return typeMapping;
 }
 private TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, TypeFlags flags, bool isList)
 {
     TypeMapping defaultMapping = (TypeMapping) base.ImportedMappings[dataType];
     if (defaultMapping != null)
     {
         return defaultMapping;
     }
     XmlSchemaType type = dataType;
     while (!type.DerivedFrom.IsEmpty)
     {
         type = this.FindType(type.DerivedFrom, TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     }
     if (type is XmlSchemaComplexType)
     {
         return null;
     }
     TypeDesc typeDesc = base.Scope.GetTypeDesc((XmlSchemaSimpleType) type);
     if ((typeDesc != null) && (typeDesc.FullName != typeof(string).FullName))
     {
         return this.ImportPrimitiveDataType(dataType, flags);
     }
     identifier = Accessor.UnescapeName(identifier);
     string name = base.GenerateUniqueTypeName(identifier);
     EnumMapping mapping2 = new EnumMapping {
         IsReference = base.Schemas.IsReference(dataType),
         TypeDesc = new TypeDesc(name, name, TypeKind.Enum, null, TypeFlags.None)
     };
     if ((dataType.Name != null) && (dataType.Name.Length > 0))
     {
         mapping2.TypeName = identifier;
     }
     mapping2.Namespace = typeNs;
     mapping2.IsFlags = isList;
     CodeIdentifiers identifiers = new CodeIdentifiers();
     XmlSchemaSimpleTypeContent content = dataType.Content;
     if (content is XmlSchemaSimpleTypeRestriction)
     {
         XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
         for (int i = 0; i < restriction.Facets.Count; i++)
         {
             object obj2 = restriction.Facets[i];
             if (obj2 is XmlSchemaEnumerationFacet)
             {
                 XmlSchemaEnumerationFacet facet = (XmlSchemaEnumerationFacet) obj2;
                 if ((typeDesc != null) && typeDesc.HasCustomFormatter)
                 {
                     XmlCustomFormatter.ToDefaultValue(facet.Value, typeDesc.FormatterName);
                 }
                 ConstantMapping mapping3 = new ConstantMapping();
                 string str2 = CodeIdentifier.MakeValid(facet.Value);
                 mapping3.Name = identifiers.AddUnique(str2, mapping3);
                 mapping3.XmlName = facet.Value;
                 mapping3.Value = i;
             }
         }
     }
     mapping2.Constants = (ConstantMapping[]) identifiers.ToArray(typeof(ConstantMapping));
     if (isList && (mapping2.Constants.Length > 0x3f))
     {
         defaultMapping = this.GetDefaultMapping(TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.CanBeAttributeValue);
         base.ImportedMappings.Add(dataType, defaultMapping);
         return defaultMapping;
     }
     base.ImportedMappings.Add(dataType, mapping2);
     base.Scope.AddTypeMapping(mapping2);
     return mapping2;
 }
 private EnumMapping ImportEnumeratedChoice(ElementAccessor[] choice, string typeNs, string typeName)
 {
     typeName = this.GenerateUniqueTypeName(Accessor.UnescapeName(typeName), typeNs);
     EnumMapping typeMapping = new EnumMapping {
         TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Enum, null, TypeFlags.None),
         TypeName = typeName,
         Namespace = typeNs,
         IsFlags = false,
         IncludeInSchema = false
     };
     if (this.GenerateOrder)
     {
         Array.Sort(choice, new ElementComparer());
     }
     CodeIdentifiers identifiers = new CodeIdentifiers();
     for (int i = 0; i < choice.Length; i++)
     {
         ElementAccessor accessor = choice[i];
         ConstantMapping mapping2 = new ConstantMapping();
         string identifier = CodeIdentifier.MakeValid(accessor.Name);
         mapping2.Name = identifiers.AddUnique(identifier, mapping2);
         mapping2.XmlName = accessor.ToString(typeNs);
         mapping2.Value = i;
     }
     typeMapping.Constants = (ConstantMapping[]) identifiers.ToArray(typeof(ConstantMapping));
     base.Scope.AddTypeMapping(typeMapping);
     return typeMapping;
 }
Exemple #15
0
        TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier) {
            EnumMapping enumMapping = (EnumMapping)mappings[dataType];
            if (enumMapping != null) return enumMapping;
            XmlSchemaSimpleType sourceDataType = FindDataType(dataType.DerivedFrom);
            TypeDesc sourceTypeDesc = scope.GetTypeDesc(sourceDataType);
            if (sourceTypeDesc != null && sourceTypeDesc != scope.GetTypeDesc(typeof(string)))
                return ImportPrimitiveDataType(dataType);
            string typeName = GenerateUniqueTypeName(identifier);
            enumMapping = new EnumMapping();
            enumMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0);
            enumMapping.TypeName = identifier;
            enumMapping.Namespace = typeNs;
            enumMapping.IsFlags = false;
            mappings.Add(dataType, enumMapping);
            CodeIdentifiers constants = new CodeIdentifiers();

            if (!(dataType.Content is XmlSchemaSimpleTypeRestriction))
                throw new InvalidOperationException(Res.GetString(Res.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));
            scope.AddTypeMapping(enumMapping);
            return enumMapping;
        }
 private MemberMapping[] ImportTypeMembers(XmlSchemaType type, string typeNs, string identifier, CodeIdentifiers members, CodeIdentifiers membersScope, INameScope elementsScope, ref bool needExplicitOrder, bool order, bool allowUnboundedElements)
 {
     TypeItems typeItems = this.GetTypeItems(type);
     bool mixed = IsMixed(type);
     if (mixed)
     {
         XmlSchemaType type2 = type;
         while (!type2.DerivedFrom.IsEmpty)
         {
             type2 = this.FindType(type2.DerivedFrom, TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue);
             if (IsMixed(type2))
             {
                 mixed = false;
                 break;
             }
         }
     }
     if (typeItems.Particle != null)
     {
         this.ImportGroup(typeItems.Particle, identifier, members, membersScope, elementsScope, typeNs, mixed, ref needExplicitOrder, order, typeItems.IsUnbounded, allowUnboundedElements);
     }
     for (int i = 0; i < typeItems.Attributes.Count; i++)
     {
         object obj2 = typeItems.Attributes[i];
         if (obj2 is XmlSchemaAttribute)
         {
             this.ImportAttributeMember((XmlSchemaAttribute) obj2, identifier, members, membersScope, typeNs);
         }
         else if (obj2 is XmlSchemaAttributeGroupRef)
         {
             XmlQualifiedName refName = ((XmlSchemaAttributeGroupRef) obj2).RefName;
             this.ImportAttributeGroupMembers(this.FindAttributeGroup(refName), identifier, members, membersScope, refName.Namespace);
         }
     }
     if (typeItems.AnyAttribute != null)
     {
         this.ImportAnyAttributeMember(typeItems.AnyAttribute, members, membersScope);
     }
     if ((typeItems.baseSimpleType != null) || ((typeItems.Particle == null) && mixed))
     {
         this.ImportTextMember(members, membersScope, mixed ? null : typeItems.baseSimpleType);
     }
     this.ImportXmlnsDeclarationsMember(type, members, membersScope);
     return (MemberMapping[]) members.ToArray(typeof(MemberMapping));
 }
Exemple #17
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(SR.Format(SR.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);
        }
        private TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, TypeFlags flags, bool isList)
        {
            TypeMapping mapping = (TypeMapping)ImportedMappings[dataType];
            if (mapping != null)
                return mapping;

            XmlSchemaType sourceType = dataType;
            while (!sourceType.DerivedFrom.IsEmpty)
            {
                sourceType = FindType(sourceType.DerivedFrom, TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
            }
            if (sourceType is XmlSchemaComplexType) return null;
            TypeDesc sourceTypeDesc = Scope.GetTypeDesc((XmlSchemaSimpleType)sourceType);
            if (sourceTypeDesc != null && sourceTypeDesc.FullName != typeof(string).FullName)
                return ImportPrimitiveDataType(dataType, flags);
            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);
            if (dataType.Name != null && dataType.Name.Length > 0)
                enumMapping.TypeName = identifier;
            enumMapping.Namespace = typeNs;
            enumMapping.IsFlags = isList;

            CodeIdentifiers constants = new CodeIdentifiers();
            XmlSchemaSimpleTypeContent content = dataType.Content;

            if (content is XmlSchemaSimpleTypeRestriction)
            {
                XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)content;
                for (int i = 0; i < restriction.Facets.Count; i++)
                {
                    object facet = restriction.Facets[i];
                    if (!(facet is XmlSchemaEnumerationFacet)) continue;
                    XmlSchemaEnumerationFacet enumeration = (XmlSchemaEnumerationFacet)facet;
                    // validate the enumeration value
                    if (sourceTypeDesc != null && sourceTypeDesc.HasCustomFormatter)
                    {
                        XmlCustomFormatter.ToDefaultValue(enumeration.Value, sourceTypeDesc.FormatterName);
                    }
                    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 = GetDefaultMapping(TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.CanBeAttributeValue);
                ImportedMappings.Add(dataType, mapping);
                return mapping;
            }
            ImportedMappings.Add(dataType, enumMapping);
            Scope.AddTypeMapping(enumMapping);
            return enumMapping;
        }
        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(Res.GetString(Res.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;
        }
 private TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, bool isList)
 {
     TypeMapping mapping = (TypeMapping) base.ImportedMappings[dataType];
     if (mapping != null)
     {
         return mapping;
     }
     XmlSchemaSimpleType type = this.FindDataType(dataType.DerivedFrom);
     TypeDesc typeDesc = base.Scope.GetTypeDesc(type);
     if ((typeDesc != null) && (typeDesc != base.Scope.GetTypeDesc(typeof(string))))
     {
         return this.ImportPrimitiveDataType(dataType);
     }
     identifier = Accessor.UnescapeName(identifier);
     string name = base.GenerateUniqueTypeName(identifier);
     EnumMapping mapping2 = new EnumMapping {
         IsReference = base.Schemas.IsReference(dataType),
         TypeDesc = new TypeDesc(name, name, TypeKind.Enum, null, TypeFlags.None),
         TypeName = identifier,
         Namespace = typeNs,
         IsFlags = isList
     };
     CodeIdentifiers identifiers = new CodeIdentifiers();
     if (!(dataType.Content is XmlSchemaSimpleTypeRestriction))
     {
         throw new InvalidOperationException(Res.GetString("XmlInvalidEnumContent", new object[] { dataType.Content.GetType().Name, identifier }));
     }
     XmlSchemaSimpleTypeRestriction content = (XmlSchemaSimpleTypeRestriction) dataType.Content;
     for (int i = 0; i < content.Facets.Count; i++)
     {
         object obj2 = content.Facets[i];
         if (obj2 is XmlSchemaEnumerationFacet)
         {
             XmlSchemaEnumerationFacet facet = (XmlSchemaEnumerationFacet) obj2;
             ConstantMapping mapping3 = new ConstantMapping();
             string str2 = CodeIdentifier.MakeValid(facet.Value);
             mapping3.Name = identifiers.AddUnique(str2, mapping3);
             mapping3.XmlName = facet.Value;
             mapping3.Value = i;
         }
     }
     mapping2.Constants = (ConstantMapping[]) identifiers.ToArray(typeof(ConstantMapping));
     if (isList && (mapping2.Constants.Length > 0x3f))
     {
         mapping = new PrimitiveMapping {
             TypeDesc = base.Scope.GetTypeDesc(typeof(string)),
             TypeName = mapping.TypeDesc.DataType.Name
         };
         base.ImportedMappings.Add(dataType, mapping);
         return mapping;
     }
     base.ImportedMappings.Add(dataType, mapping2);
     base.Scope.AddTypeMapping(mapping2);
     return mapping2;
 }