CreateTypeManager() static private method

static private CreateTypeManager ( XmlQualifiedName rootElementName, bool enableServiceReference, CodeStatementCollection typeDictionaryStatements, CodeStatementCollection elementDictionaryStatements, CodeStatementCollection wrapperDictionaryStatements ) : CodeTypeDeclaration
rootElementName System.Xml.XmlQualifiedName
enableServiceReference bool
typeDictionaryStatements System.CodeDom.CodeStatementCollection
elementDictionaryStatements System.CodeDom.CodeStatementCollection
wrapperDictionaryStatements System.CodeDom.CodeStatementCollection
return System.CodeDom.CodeTypeDeclaration
        private void CreateTypeManager()
        {
            string        rootClrNamespace  = this.settings.GetClrNamespace(this.rootElementName.Namespace);
            CodeNamespace rootCodeNamespace = null;

            if (!this.codeNamespacesTable.TryGetValue(rootClrNamespace, out rootCodeNamespace))
            {
                rootCodeNamespace = this.codeNamespacesTable.Values.FirstOrDefault <CodeNamespace>();
            }
            if (rootCodeNamespace != null)
            {
                rootCodeNamespace.Types.Add(TypeBuilder.CreateTypeManager(this.rootElementName, this.settings.EnableServiceReference, CodeDomTypesGenerator.typeDictionaryAddStatements, CodeDomTypesGenerator.elementDictionaryAddStatements, CodeDomTypesGenerator.wrapperDictionaryAddStatements));
                CodeNamespaceImport rootImport = new CodeNamespaceImport(rootCodeNamespace.Name);
                foreach (CodeNamespace cns in this.codeNamespacesTable.Values)
                {
                    if (cns != rootCodeNamespace)
                    {
                        if (rootCodeNamespace.Name.Length > 0)
                        {
                            cns.Imports.Add(rootImport);
                        }
                        if (cns.Name.Length > 0)
                        {
                            rootCodeNamespace.Imports.Add(new CodeNamespaceImport(cns.Name));
                        }
                    }
                }
            }
        }
Example #2
0
        private void CreateTypeManager()
        {
            string        rootClrNamespace  = settings.GetClrNamespace(rootElementName.Namespace);
            CodeNamespace rootCodeNamespace = null;

            if (!codeNamespacesTable.TryGetValue(rootClrNamespace, out rootCodeNamespace)) //This might happen if the schema set has no global elements and only global types
            {
                rootCodeNamespace = codeNamespacesTable.Values.FirstOrDefault();           //then you can create a root tag with xsi:type
            }
            if (rootCodeNamespace != null)                                                 //It might be null if schema has only simple typed global elements or simple types which we are ignoring for now
            {
                rootCodeNamespace.Types.Add(TypeBuilder.CreateTypeManager(rootElementName, settings.EnableServiceReference, typeDictionaryAddStatements, elementDictionaryAddStatements, wrapperDictionaryAddStatements));
                //Add using statements in the rest of the namespaces for the root namespace to avoid error on TypeManager reference
                //Add using statements in the root namespace for the rest of the namespaces to avoid errors while building type dictionaries
                CodeNamespaceImport rootImport = new CodeNamespaceImport(rootCodeNamespace.Name);
                foreach (CodeNamespace cns in codeNamespacesTable.Values)
                {
                    if (cns != rootCodeNamespace)
                    {
                        if (rootCodeNamespace.Name.Length > 0)
                        {
                            cns.Imports.Add(rootImport);
                        }
                        if (cns.Name.Length > 0)
                        {
                            rootCodeNamespace.Imports.Add(new CodeNamespaceImport(cns.Name));
                        }
                    }
                }
            }
        }