public IEnumerable <CodeNamespace> GenerateTypes(ClrMappingInfo binding)
        {
            if (binding == null)
            {
                throw new ArgumentException("binding");
            }

            nameMappings = binding.NameMappings;
            Debug.Assert(nameMappings != null);
            foreach (ClrTypeInfo type in binding.Types)
            {
                if (type.IsWrapper)
                {
                    if (wrapperRootElements == null)
                    {
                        wrapperRootElements = new List <ClrWrapperTypeInfo>();
                    }

                    wrapperRootElements.Add(type as ClrWrapperTypeInfo);
                }
                else
                {
                    codeNamespace = GetCodeNamespace(type.clrtypeNs);
                    ClrSimpleTypeInfo stInfo = type as ClrSimpleTypeInfo;
                    if (stInfo != null)
                    {
                        if (stInfo is EnumSimpleTypeInfo enumTypeInfo)
                        {
                            codeNamespace.Types.Add(TypeBuilder.CreateEnumType(enumTypeInfo, settings));
                        }
                        codeNamespace.Types.Add(TypeBuilder.CreateSimpleType(stInfo, nameMappings, settings));
                    }
                    else
                    {
                        CodeTypeDeclaration
                            decl = ProcessType(type as ClrContentTypeInfo, null, true); //Sets current codeNamespace
                        codeNamespace.Types.Add(decl);

                        if (type.IsRootElement)
                        {
                            List <CodeTypeDeclaration> types;

                            if (!xroots.TryGetValue(codeNamespace, out types))
                            {
                                types = new List <CodeTypeDeclaration>();
                                xroots.Add(codeNamespace, types);
                            }

                            types.Add(decl);
                        }
                    }
                }
            }

            ProcessWrapperTypes();
            CreateTypeManager();
            CreateXRoots();
            return(codeNamespacesTable.Values);
        }
 public XsdToTypesConverter(LinqToXsdSettings configSettings)
 {
     this.configSettings = configSettings;
     symbolTable = new GlobalSymbolTable(configSettings);
     localSymbolTable = new LocalSymbolTable(configSettings);
     binding = new ClrMappingInfo();
     textPropInheritanceTracker = new Dictionary<XmlSchemaType, ClrPropertyInfo>();
     substitutionGroups = new Dictionary<XmlQualifiedName, ArrayList>();
 }
 public XsdToTypesConverter(LinqToXsdSettings configSettings)
 {
     this.configSettings        = configSettings;
     symbolTable                = new GlobalSymbolTable(configSettings);
     localSymbolTable           = new LocalSymbolTable();
     binding                    = new ClrMappingInfo();
     textPropInheritanceTracker = new Dictionary <XmlSchemaType, ClrPropertyInfo>();
     substitutionGroups         = new Dictionary <XmlQualifiedName, ArrayList>();
 }
        public IEnumerable <CodeNamespace> GenerateTypes(ClrMappingInfo binding)
        {
            List <CodeTypeDeclaration> types;

            if (binding == null)
            {
                throw new ArgumentException("binding");
            }
            this.nameMappings = binding.NameMappings;
            Debug.Assert(this.nameMappings != null);
            foreach (ClrTypeInfo type in binding.Types)
            {
                if (!type.IsWrapper)
                {
                    this.codeNamespace = this.GetCodeNamespace(type.clrtypeNs);
                    ClrSimpleTypeInfo stInfo = type as ClrSimpleTypeInfo;
                    if (stInfo == null)
                    {
                        CodeTypeDeclaration decl = this.ProcessType(type as ClrContentTypeInfo, null, true);
                        this.codeNamespace.Types.Add(decl);
                        if (type.IsRootElement)
                        {
                            if (!this.xroots.TryGetValue(this.codeNamespace, out types))
                            {
                                types = new List <CodeTypeDeclaration>();
                                this.xroots.Add(this.codeNamespace, types);
                            }
                            types.Add(decl);
                        }
                    }
                    else
                    {
                        this.codeNamespace.Types.Add(TypeBuilder.CreateSimpleType(stInfo, this.nameMappings, this.settings));
                    }
                }
                else
                {
                    if (this.wrapperRootElements == null)
                    {
                        this.wrapperRootElements = new List <ClrWrapperTypeInfo>();
                    }
                    this.wrapperRootElements.Add(type as ClrWrapperTypeInfo);
                }
            }
            this.ProcessWrapperTypes();
            this.CreateTypeManager();
            this.CreateXRoots();
            return(this.codeNamespacesTable.Values);
        }
        public IEnumerable<CodeNamespace> GenerateTypes(ClrMappingInfo binding)
        {
            if (binding == null)
            {
                throw new ArgumentException("binding");
            }
            nameMappings = binding.NameMappings;
            Debug.Assert(nameMappings != null);
            foreach(ClrTypeInfo type in binding.Types)
            {
                if (type.IsWrapper) {
                    if (wrapperRootElements == null) {
                        wrapperRootElements = new List<ClrWrapperTypeInfo>();
                    }
                    wrapperRootElements.Add(type as ClrWrapperTypeInfo);

                }
                else {
                    codeNamespace = GetCodeNamespace(type.clrtypeNs);
                    ClrSimpleTypeInfo stInfo = type as ClrSimpleTypeInfo;
                    if (stInfo != null) {
                        codeNamespace.Types.Add(TypeBuilder.CreateSimpleType(stInfo, nameMappings, settings));
                    }
                    else {
                        CodeTypeDeclaration decl = ProcessType(type as ClrContentTypeInfo, null, true); //Sets current codeNamespace
                        codeNamespace.Types.Add(decl);

                        if (type.IsRootElement) {
                            List<CodeTypeDeclaration> types;

                            if (!xroots.TryGetValue(codeNamespace, out types)) {
                                types = new List<CodeTypeDeclaration>();
                                xroots.Add(codeNamespace, types);
                            }

                            types.Add(decl);
                        }
                    }
                }
            }
            ProcessWrapperTypes();
            CreateTypeManager();
            CreateXRoots();
            return codeNamespacesTable.Values;
        }
Exemple #6
0
        public IEnumerable <CodeNamespace> GenerateTypes(ClrMappingInfo binding)
        {
            if (binding == null)
            {
                throw new ArgumentException("binding");
            }

            nameMappings = binding.NameMappings;
            Debug.Assert(nameMappings != null);
            foreach (ClrTypeInfo type in binding.Types)
            {
                if (type.IsWrapper)
                {
                    if (wrapperRootElements == null)
                    {
                        wrapperRootElements = new List <ClrWrapperTypeInfo>();
                    }

                    wrapperRootElements.Add(type as ClrWrapperTypeInfo);
                }
                else
                {
                    codeNamespace = GetCodeNamespace(type.clrtypeNs);
                    ClrSimpleTypeInfo stInfo = type as ClrSimpleTypeInfo;
                    if (stInfo != null)
                    {
                        if (stInfo is EnumSimpleTypeInfo enumTypeInfo)
                        {
                            var enumType = TypeBuilder.CreateEnumType(enumTypeInfo, settings, stInfo);
                            codeNamespace.Types.Add(enumType);
                            var enumsInOtherTypes = codeNamespace.DescendentTypeScopedEnumDeclarations();
                            // if an enum is defined in another type, remove it, if it is the same as the global (namespace scoped type)
                            if (enumsInOtherTypes.EqualEnumDeclarationExists(enumType))
                            {
                                var typeWithDuplicateEnum = codeNamespace.TypeWithEnumDeclaration(enumType);
                                var duplicateEnum         = typeWithDuplicateEnum.Members.OfType <CodeTypeDeclaration>()
                                                            .First(c => c.IsEqualEnumDeclaration(enumType));
                                typeWithDuplicateEnum.Members.Remove(duplicateEnum);
                            }
                        }
                        codeNamespace.Types.Add(TypeBuilder.CreateSimpleType(stInfo, nameMappings, settings));
                    }
                    else
                    {
                        CodeTypeDeclaration
                            decl = ProcessType(type as ClrContentTypeInfo, null, true); //Sets current codeNamespace
                        codeNamespace.Types.Add(decl);

                        if (type.IsRootElement)
                        {
                            List <CodeTypeDeclaration> types;

                            if (!xroots.TryGetValue(codeNamespace, out types))
                            {
                                types = new List <CodeTypeDeclaration>();
                                xroots.Add(codeNamespace, types);
                            }

                            types.Add(decl);
                        }
                    }
                }
            }

            ProcessWrapperTypes();
            CreateTypeManager();
            CreateXRoots();
            return(codeNamespacesTable.Values);
        }