Ejemplo n.º 1
0
        private IEnumerable <CodeTypeDeclaration> GetAllEnumsDefinedAlready()
        {
            var enumsUnderNamespace             = codeNamespace.DescendentTypeScopedEnumDeclarations();
            var enumsInOtherTypesUnderNamespace = codeNamespace.NamespaceScopedEnumDeclarations();
            var enumsInCurrentType = typeBuilder.TypeDeclaration.Members.OfType <CodeTypeDeclaration>().Where(c => c.IsEnum);

            return(enumsUnderNamespace.Union(enumsInCurrentType).Union(enumsInOtherTypesUnderNamespace));
        }
Ejemplo n.º 2
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);
        }