Skip to content

[Code generation] How do you add a trailing comma to a generated enum? #73814

Closed Answered by CyrusNajmabadi
dulcineachau asked this question in Q&A
Discussion options

You must be logged in to vote

Here's an example of how we do it in roslyn:

internal static EnumDeclarationSyntax AddEnumMemberTo(EnumDeclarationSyntax destination, IFieldSymbol enumMember, CSharpCodeGenerationContextInfo info, CancellationToken cancellationToken)
{
var members = new List<SyntaxNodeOrToken>();
members.AddRange(destination.Members.GetWithSeparators());
var member = GenerateEnumMemberDeclaration(enumMember, destination, info, cancellationToken);
if (members.Count == 0)
{
members.Add(member);
}
else if (members.

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@dulcineachau
Comment options

@CyrusNajmabadi
Comment options

@CyrusNajmabadi
Comment options

Answer selected by dulcineachau
@dulcineachau
Comment options

@dulcineachau
Comment options

@dulcineachau
Comment options

@CyrusNajmabadi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants