CreateSimpleType() static private method

static private CreateSimpleType ( Xml.Schema.Linq.CodeGen.ClrSimpleTypeInfo typeInfo, string>.Dictionary nameMappings, LinqToXsdSettings settings ) : CodeTypeDeclaration
typeInfo Xml.Schema.Linq.CodeGen.ClrSimpleTypeInfo
nameMappings string>.Dictionary
settings LinqToXsdSettings
return System.CodeDom.CodeTypeDeclaration
コード例 #1
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)
                        {
                            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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 private void ProcessNestedTypes(List <ClrTypeInfo> anonymousTypes, CodeTypeDeclaration parentTypeDecl, string parentIdentifier)
 {
     foreach (ClrTypeInfo nestedType in anonymousTypes)
     {
         ClrSimpleTypeInfo   stInfo = nestedType as ClrSimpleTypeInfo;
         CodeTypeDeclaration decl   = null;
         if (stInfo != null)
         {
             decl = TypeBuilder.CreateSimpleType(stInfo, nameMappings, settings);
             decl.TypeAttributes = System.Reflection.TypeAttributes.NestedPrivate; //Anonymous simple types are private within the scope of the parent class
         }
         else
         {
             decl = ProcessType(nestedType as ClrContentTypeInfo, parentIdentifier, false);
         }
         parentTypeDecl.Members.Add(decl);
     }
 }
コード例 #4
0
 private void ProcessNestedTypes(List <ClrTypeInfo> anonymousTypes, CodeTypeDeclaration parentTypeDecl, string parentIdentifier)
 {
     foreach (ClrTypeInfo nestedType in anonymousTypes)
     {
         ClrSimpleTypeInfo   stInfo = nestedType as ClrSimpleTypeInfo;
         CodeTypeDeclaration decl   = null;
         if (stInfo == null)
         {
             decl = this.ProcessType(nestedType as ClrContentTypeInfo, parentIdentifier, false);
         }
         else
         {
             decl = TypeBuilder.CreateSimpleType(stInfo, this.nameMappings, this.settings);
             decl.TypeAttributes = TypeAttributes.NestedPrivate;
         }
         parentTypeDecl.Members.Add(decl);
     }
 }
コード例 #5
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);
        }