Skip to content

Commit

Permalink
Use interpolation over string concat and join
Browse files Browse the repository at this point in the history
  • Loading branch information
Mafii committed Sep 25, 2024
1 parent 1334c9d commit 920725b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Funcky.DiscriminatedUnion.SourceGeneration/Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ private static void WriteJsonDerivedTypeAttribute(IndentedTextWriter writer, Dis
}

private static CollectingInterpolatedStringHandler FormatMatchMethodDeclaration(string genericTypeName, IEnumerable<DiscriminatedUnionVariant> variants)
=> $"{genericTypeName} Match<{genericTypeName}>({string.Join(", ", variants.Select(variant => $"global::System.Func<{variant.LocalTypeName}, {genericTypeName}> {FormatIdentifier(variant.ParameterName)}"))})";
=> $"{genericTypeName} Match<{genericTypeName}>({variants.JoinToInterpolation(v => $"global::System.Func<{v.LocalTypeName}, {genericTypeName})> {FormatIdentifier(v.ParameterName)}", ", ")})";

private static string FormatSwitchMethodDeclaration(IEnumerable<DiscriminatedUnionVariant> variants)
=> $"void Switch({string.Join(", ", variants.Select(variant => $"global::System.Action<{variant.LocalTypeName}> {FormatIdentifier(variant.ParameterName)}"))})";
=> $"void Switch({variants.JoinToInterpolation(v => $"global::System.Action<{v.LocalTypeName}> {FormatIdentifier(v.ParameterName)}", ", "))})";

Check failure on line 179 in Funcky.DiscriminatedUnion.SourceGeneration/Emitter.cs

View workflow job for this annotation

GitHub Actions / build

Syntax error, '}' expected

Check failure on line 179 in Funcky.DiscriminatedUnion.SourceGeneration/Emitter.cs

View workflow job for this annotation

GitHub Actions / build

Unexpected token ')'

Check failure on line 179 in Funcky.DiscriminatedUnion.SourceGeneration/Emitter.cs

View workflow job for this annotation

GitHub Actions / build

Syntax error, '}' expected

Check failure on line 179 in Funcky.DiscriminatedUnion.SourceGeneration/Emitter.cs

View workflow job for this annotation

GitHub Actions / build

Unexpected token ')'

Check failure on line 179 in Funcky.DiscriminatedUnion.SourceGeneration/Emitter.cs

View workflow job for this annotation

GitHub Actions / nupkg

Syntax error, '}' expected

Check failure on line 179 in Funcky.DiscriminatedUnion.SourceGeneration/Emitter.cs

View workflow job for this annotation

GitHub Actions / nupkg

Unexpected token ')'

private static CollectingInterpolatedStringHandler FormatPartialTypeDeclaration(TypeDeclarationSyntax typeDeclaration)
=> typeDeclaration is RecordDeclarationSyntax recordDeclaration
Expand All @@ -186,8 +186,8 @@ private static CollectingInterpolatedStringHandler FormatPartialTypeDeclaration(
private static CollectingInterpolatedStringHandler CombineTokens(params object[] tokens)
=> tokens.Select(t => t.ToString()).Where(t => !string.IsNullOrEmpty(t)).JoinToInterpolation(" ");

private static string FormatIdentifier(string identifier)
=> IsIdentifier(identifier) ? '@' + identifier : identifier;
private static CollectingInterpolatedStringHandler FormatIdentifier(string identifier)
=> $"{(IsIdentifier(identifier) ? "@" : string.Empty)}{identifier}";

private static bool IsIdentifier(string identifier)
=> SyntaxFacts.GetKeywordKind(identifier) != SyntaxKind.None;
Expand Down

0 comments on commit 920725b

Please sign in to comment.