private static CodeTypeDeclaration ToCodeTypeDeclaration(MessageDefinitions.Data.Enum enumeration) { CodeTypeDeclaration codeTypeDeclaration = new CodeTypeDeclaration() { Name = enumeration.Name, IsEnum = true }; // Add summary comments CodeCommentStatement[] summaryCommentStatements = CodeCommentStatementHelper.GetSummaryCodeCommentStatements(enumeration.Description); codeTypeDeclaration.Comments.AddRange(summaryCommentStatements); if (enumeration.IsNameTransformed) { // Add remarks comments CodeCommentStatement[] remarksCommentStatements = CodeCommentStatementHelper.GetRemarksCodeCommentStatements(enumeration.XmlDefinition.Name); codeTypeDeclaration.Comments.AddRange(remarksCommentStatements); } // Add values foreach (EnumEntry enumEntry in enumeration.Entries) { CodeMemberField field = ToCodeMemberField(enumEntry); codeTypeDeclaration.Members.Add(field); } return(codeTypeDeclaration); }
private static void GenerateEnumFile(EnumGenerationParams pParams, MessageDefinitions.Data.Enum enumeration, TypeInfo typeInfo, CodeGeneratorOptions options, CodeDomProvider codeProvider) { string filename = TypeInfoHelper.GetFilename(typeInfo); String filePath = Path.Combine(pParams.OutputPath, filename); CodeCompileUnit unit = EnumGeneratorHelper.CreateCodeCompileUnit(typeInfo, enumeration); codeProvider.GenerateCodeFromCompileUnit(unit, options, filePath); }
public static CodeCompileUnit CreateCodeCompileUnit(TypeInfo typeInfo, MessageDefinitions.Data.Enum enumeration) { CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); CodeNamespace globalNamespace = new CodeNamespace(String.Empty); codeCompileUnit.Namespaces.Add(globalNamespace); // using globalNamespace.Imports.Add(new CodeNamespaceImport("System")); globalNamespace.Imports.Add(new CodeNamespaceImport("System.ComponentModel")); // Generate the namespace CodeNamespace codeNamespace = new CodeNamespace(typeInfo.Namespace); codeCompileUnit.Namespaces.Add(codeNamespace); CodeTypeDeclaration enumTypeDeclaration = ToCodeTypeDeclaration(enumeration); // Add enum to the namespace codeNamespace.Types.Add(enumTypeDeclaration); return(codeCompileUnit); }