public string Convert() { NamespaceDeclarationSyntax @namespace = null !; if (!string.IsNullOrEmpty(EnumNamespace)) { @namespace = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.ParseName(EnumNamespace)); } EnumMemberDeclarationSyntax[] enumMembers = Values .OrderBy(x => x.Value) .Select(x => SyntaxFactory.EnumMemberDeclaration(x.Key)) .ToArray(); EnumDeclarationSyntax @enum = SyntaxFactory.EnumDeclaration(EnumName) .AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword)) .AddMembers(enumMembers); string generatedCode = @namespace is not null ? @namespace.AddMembers(@enum).NormalizeWhitespace().ToFullString() : @enum.NormalizeWhitespace().ToFullString(); return(generatedCode); }