From 920725b9a8ce0a2e6d2100bf94bfb0f897897783 Mon Sep 17 00:00:00 2001 From: Mathias Fischler Date: Wed, 25 Sep 2024 13:31:50 +0200 Subject: [PATCH] Use interpolation over string concat and join --- Funcky.DiscriminatedUnion.SourceGeneration/Emitter.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Funcky.DiscriminatedUnion.SourceGeneration/Emitter.cs b/Funcky.DiscriminatedUnion.SourceGeneration/Emitter.cs index 09db2fe..4fa40e1 100644 --- a/Funcky.DiscriminatedUnion.SourceGeneration/Emitter.cs +++ b/Funcky.DiscriminatedUnion.SourceGeneration/Emitter.cs @@ -173,10 +173,10 @@ private static void WriteJsonDerivedTypeAttribute(IndentedTextWriter writer, Dis } private static CollectingInterpolatedStringHandler FormatMatchMethodDeclaration(string genericTypeName, IEnumerable 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 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)}", ", "))})"; private static CollectingInterpolatedStringHandler FormatPartialTypeDeclaration(TypeDeclarationSyntax typeDeclaration) => typeDeclaration is RecordDeclarationSyntax recordDeclaration @@ -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;