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 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); }