From f5bae1cbf3b878a0b7fead72f2e1dbf89cfb9150 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 23 Feb 2026 15:40:03 +1100 Subject: [PATCH] use char instead of string for joins --- .../Base/AsyncMethodSignatureRewriter.cs | 2 +- .../Generators/AssertionExtensionGenerator.cs | 2 +- .../Generators/AssertionMethodGenerator.cs | 2 +- .../Generators/MethodAssertionGenerator.cs | 2 +- TUnit.Assertions/Extensions/AssertionExtensions.cs | 2 +- TUnit.Core.SourceGenerator/Extensions/TypeExtensions.cs | 2 +- .../Generators/HookMetadataGenerator.cs | 2 +- .../Generators/PropertyInjectionSourceGenerator.cs | 2 +- .../Generators/TestMetadataGenerator.cs | 2 +- TUnit.Core/Extensions/ReflectionExtensions.cs | 2 +- TUnit.Core/Extensions/TestContextExtensions.cs | 2 +- TUnit.Core/GenericTestMetadata.cs | 2 +- TUnit.Engine/Discovery/ReflectionHookDiscoveryService.cs | 2 +- TUnit.Engine/Services/FilterParser.cs | 2 +- TUnit.Engine/Services/TestFilterService.cs | 2 +- TUnit.Mocks.Http/RequestMatcher.cs | 4 ++-- TUnit.Mocks.SourceGenerator/Builders/MockImplBuilder.cs | 4 ++-- TUnit.Mocks.SourceGenerator/Builders/MockSetupBuilder.cs | 2 +- TUnit.Mocks.SourceGenerator/Builders/MockVerifyBuilder.cs | 2 +- TUnit.Mocks.SourceGenerator/Discovery/MemberDiscovery.cs | 6 +++--- .../Extensions/TypeSymbolExtensions.cs | 4 ++-- TUnit.Mocks/Mock.cs | 2 +- 22 files changed, 27 insertions(+), 27 deletions(-) diff --git a/TUnit.Analyzers.CodeFixers/Base/AsyncMethodSignatureRewriter.cs b/TUnit.Analyzers.CodeFixers/Base/AsyncMethodSignatureRewriter.cs index 783a5d0021..02b9777f50 100644 --- a/TUnit.Analyzers.CodeFixers/Base/AsyncMethodSignatureRewriter.cs +++ b/TUnit.Analyzers.CodeFixers/Base/AsyncMethodSignatureRewriter.cs @@ -84,7 +84,7 @@ private static string GetMethodKey(MethodDeclarationSyntax node) // Build a key from class name, method name, and parameter types var className = node.Ancestors().OfType().FirstOrDefault()?.Identifier.Text ?? ""; var methodName = node.Identifier.Text; - var parameters = string.Join(",", node.ParameterList.Parameters.Select(p => p.Type?.ToString() ?? "")); + var parameters = string.Join(',', node.ParameterList.Parameters.Select(p => p.Type?.ToString() ?? "")); return $"{className}.{methodName}({parameters})"; } diff --git a/TUnit.Assertions.SourceGenerator/Generators/AssertionExtensionGenerator.cs b/TUnit.Assertions.SourceGenerator/Generators/AssertionExtensionGenerator.cs index fffcd9b3a8..5778c0cfc8 100644 --- a/TUnit.Assertions.SourceGenerator/Generators/AssertionExtensionGenerator.cs +++ b/TUnit.Assertions.SourceGenerator/Generators/AssertionExtensionGenerator.cs @@ -422,7 +422,7 @@ private static void GenerateExtensionMethod( if (allConstraints.Count > 0) { sourceBuilder.AppendLine(); - sourceBuilder.Append($" {string.Join(" ", allConstraints)}"); + sourceBuilder.Append($" {string.Join(' ', allConstraints)}"); } sourceBuilder.AppendLine(); diff --git a/TUnit.Assertions.SourceGenerator/Generators/AssertionMethodGenerator.cs b/TUnit.Assertions.SourceGenerator/Generators/AssertionMethodGenerator.cs index 116e99f278..b9ee66b263 100644 --- a/TUnit.Assertions.SourceGenerator/Generators/AssertionMethodGenerator.cs +++ b/TUnit.Assertions.SourceGenerator/Generators/AssertionMethodGenerator.cs @@ -1167,7 +1167,7 @@ private static void GenerateMethod(StringBuilder sourceBuilder, string targetTyp { // Add generic constraints from the method sourceBuilder.AppendLine(); - sourceBuilder.Append($" {string.Join(" ", genericConstraints)}"); + sourceBuilder.Append($" {string.Join(' ', genericConstraints)}"); } sourceBuilder.AppendLine(); diff --git a/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs b/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs index be0db41b01..b88b7bda8e 100644 --- a/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs +++ b/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs @@ -1073,7 +1073,7 @@ private static string GenerateClassName(AssertionMethodData data) } // Include parameter types to distinguish overloads - var paramTypes = string.Join("_", data.AdditionalParameters.Select(p => p.SimpleTypeName)); + var paramTypes = string.Join('_', data.AdditionalParameters.Select(p => p.SimpleTypeName)); return $"{targetTypeName}_{methodName}_{paramTypes}_Assertion"; } diff --git a/TUnit.Assertions/Extensions/AssertionExtensions.cs b/TUnit.Assertions/Extensions/AssertionExtensions.cs index c2a380f459..405b1bd879 100644 --- a/TUnit.Assertions/Extensions/AssertionExtensions.cs +++ b/TUnit.Assertions/Extensions/AssertionExtensions.cs @@ -683,7 +683,7 @@ private static string GetMemberPath(Expression 0 ? string.Join(".", parts) : "Unknown"; + return parts.Count > 0 ? string.Join('.', parts) : "Unknown"; } /// diff --git a/TUnit.Core.SourceGenerator/Extensions/TypeExtensions.cs b/TUnit.Core.SourceGenerator/Extensions/TypeExtensions.cs index ba44c376b4..8690b1b911 100644 --- a/TUnit.Core.SourceGenerator/Extensions/TypeExtensions.cs +++ b/TUnit.Core.SourceGenerator/Extensions/TypeExtensions.cs @@ -266,6 +266,6 @@ public static string GetNestedClassName(this INamedTypeSymbol typeSymbol) typeHierarchy.Reverse(); // Join with '+' separator (matching .NET Type.FullName convention for nested types) - return string.Join("+", typeHierarchy); + return string.Join('+', typeHierarchy); } } diff --git a/TUnit.Core.SourceGenerator/Generators/HookMetadataGenerator.cs b/TUnit.Core.SourceGenerator/Generators/HookMetadataGenerator.cs index 267ef14ab7..5528bc2561 100644 --- a/TUnit.Core.SourceGenerator/Generators/HookMetadataGenerator.cs +++ b/TUnit.Core.SourceGenerator/Generators/HookMetadataGenerator.cs @@ -407,7 +407,7 @@ private static string GetSafeFileName(HookModel hook) // Only add if there are parameters (matches main branch behavior - no _0_ suffix for empty params) if (hook.Parameters.Length > 0) { - var paramTypes = string.Join("_", hook.Parameters.Select(p => SanitizeForFileName(GetSimpleTypeName(p.TypeName)))); + var paramTypes = string.Join('_', hook.Parameters.Select(p => SanitizeForFileName(GetSimpleTypeName(p.TypeName)))); baseName += $"__{paramTypes}"; } diff --git a/TUnit.Core.SourceGenerator/Generators/PropertyInjectionSourceGenerator.cs b/TUnit.Core.SourceGenerator/Generators/PropertyInjectionSourceGenerator.cs index 9bc3728075..48ee6dbde4 100644 --- a/TUnit.Core.SourceGenerator/Generators/PropertyInjectionSourceGenerator.cs +++ b/TUnit.Core.SourceGenerator/Generators/PropertyInjectionSourceGenerator.cs @@ -1258,7 +1258,7 @@ private static string GetAssemblyQualifiedTypeName(ITypeSymbol typeSymbol) } } - return constraintParts.Count > 0 ? string.Join(" ", constraintParts) : null; + return constraintParts.Count > 0 ? string.Join(' ', constraintParts) : null; } #endregion diff --git a/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs b/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs index b51eab2515..7dd3770743 100644 --- a/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs +++ b/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs @@ -2831,7 +2831,7 @@ private static string BuildTypeKey(IEnumerable types) { formattedTypes[i] = typesList[i].ToDisplayString(DisplayFormats.FullyQualifiedGenericWithoutGlobalPrefix); } - return string.Join(",", formattedTypes); + return string.Join(',', formattedTypes); } /// diff --git a/TUnit.Core/Extensions/ReflectionExtensions.cs b/TUnit.Core/Extensions/ReflectionExtensions.cs index 07b12e3a66..108a2d3328 100644 --- a/TUnit.Core/Extensions/ReflectionExtensions.cs +++ b/TUnit.Core/Extensions/ReflectionExtensions.cs @@ -13,7 +13,7 @@ internal static string GetFormattedName(this Type type) return type.Name; } - var genericArguments = string.Join(",", type.GetGenericArguments().Select(GetFormattedName)); + var genericArguments = string.Join(',', type.GetGenericArguments().Select(GetFormattedName)); var backtickIndex = type.Name.IndexOf("`", StringComparison.Ordinal); if (backtickIndex == -1) diff --git a/TUnit.Core/Extensions/TestContextExtensions.cs b/TUnit.Core/Extensions/TestContextExtensions.cs index af39629ed0..ab02fe0cc6 100644 --- a/TUnit.Core/Extensions/TestContextExtensions.cs +++ b/TUnit.Core/Extensions/TestContextExtensions.cs @@ -72,7 +72,7 @@ public static string GetClassTypeName(this TestContext context) } hierarchy.Reverse(); - return string.Join("+", hierarchy); + return string.Join('+', hierarchy); } /// diff --git a/TUnit.Core/GenericTestMetadata.cs b/TUnit.Core/GenericTestMetadata.cs index 19f1950f1a..5f7d1ae91e 100644 --- a/TUnit.Core/GenericTestMetadata.cs +++ b/TUnit.Core/GenericTestMetadata.cs @@ -40,7 +40,7 @@ public override Func null, - TestNodeUidListFilter testNodeUidListFilter => string.Join(",", + TestNodeUidListFilter testNodeUidListFilter => string.Join(',', testNodeUidListFilter.TestNodeUids.Select(x => x.Value)), TreeNodeFilter treeNodeFilter => treeNodeFilter.Filter, _ => throw new ArgumentOutOfRangeException(nameof(filter)) diff --git a/TUnit.Engine/Services/TestFilterService.cs b/TUnit.Engine/Services/TestFilterService.cs index f16c784093..6c3a7a5800 100644 --- a/TUnit.Engine/Services/TestFilterService.cs +++ b/TUnit.Engine/Services/TestFilterService.cs @@ -271,6 +271,6 @@ internal static string GetNestedClassName(ClassMetadata classMetadata) } hierarchy.Reverse(); - return string.Join("+", hierarchy); + return string.Join('+', hierarchy); } } diff --git a/TUnit.Mocks.Http/RequestMatcher.cs b/TUnit.Mocks.Http/RequestMatcher.cs index 4c4ba92625..88c4707a31 100644 --- a/TUnit.Mocks.Http/RequestMatcher.cs +++ b/TUnit.Mocks.Http/RequestMatcher.cs @@ -181,8 +181,8 @@ internal string Describe() if (_exactPath != null) parts.Add(_exactPath); if (_pathPrefix != null) parts.Add($"{_pathPrefix}*"); if (_pathPattern != null) parts.Add($"~/{_pathPattern}/"); - if (_requiredHeaders.Count > 0) parts.Add($"headers:{string.Join(",", _requiredHeaders.Keys)}"); + if (_requiredHeaders.Count > 0) parts.Add($"headers:{string.Join(',', _requiredHeaders.Keys)}"); if (_bodyContains != null) parts.Add($"body contains \"{_bodyContains}\""); - return parts.Count > 0 ? string.Join(" ", parts) : "*"; + return parts.Count > 0 ? string.Join(' ', parts) : "*"; } } diff --git a/TUnit.Mocks.SourceGenerator/Builders/MockImplBuilder.cs b/TUnit.Mocks.SourceGenerator/Builders/MockImplBuilder.cs index 646e8b3bfa..64b0520978 100644 --- a/TUnit.Mocks.SourceGenerator/Builders/MockImplBuilder.cs +++ b/TUnit.Mocks.SourceGenerator/Builders/MockImplBuilder.cs @@ -814,7 +814,7 @@ private static string GetConstraintClauses(MockMemberModel method) clauses.Add($"where {tp.Name} : {tp.Constraints}"); } } - return clauses.Count > 0 ? " " + string.Join(" ", clauses) : ""; + return clauses.Count > 0 ? " " + string.Join(' ', clauses) : ""; } /// @@ -894,7 +894,7 @@ public static string GetCompositeSafeName(MockTypeModel model) var name = model.FullyQualifiedName; if (model.AdditionalInterfaceNames.Length > 0) { - name += "_" + string.Join("_", model.AdditionalInterfaceNames); + name += "_" + string.Join('_', model.AdditionalInterfaceNames); } return GetSafeName(name); } diff --git a/TUnit.Mocks.SourceGenerator/Builders/MockSetupBuilder.cs b/TUnit.Mocks.SourceGenerator/Builders/MockSetupBuilder.cs index 632f42ef58..26675a3b35 100644 --- a/TUnit.Mocks.SourceGenerator/Builders/MockSetupBuilder.cs +++ b/TUnit.Mocks.SourceGenerator/Builders/MockSetupBuilder.cs @@ -475,6 +475,6 @@ private static string GetConstraintClauses(MockMemberModel method) clauses.Add($"where {tp.Name} : {tp.Constraints}"); } } - return clauses.Count > 0 ? " " + string.Join(" ", clauses) : ""; + return clauses.Count > 0 ? " " + string.Join(' ', clauses) : ""; } } diff --git a/TUnit.Mocks.SourceGenerator/Builders/MockVerifyBuilder.cs b/TUnit.Mocks.SourceGenerator/Builders/MockVerifyBuilder.cs index 0adb2674fb..ad7dd6ff21 100644 --- a/TUnit.Mocks.SourceGenerator/Builders/MockVerifyBuilder.cs +++ b/TUnit.Mocks.SourceGenerator/Builders/MockVerifyBuilder.cs @@ -128,6 +128,6 @@ private static string GetConstraintClauses(MockMemberModel method) clauses.Add($"where {tp.Name} : {tp.Constraints}"); } } - return clauses.Count > 0 ? " " + string.Join(" ", clauses) : ""; + return clauses.Count > 0 ? " " + string.Join(' ', clauses) : ""; } } diff --git a/TUnit.Mocks.SourceGenerator/Discovery/MemberDiscovery.cs b/TUnit.Mocks.SourceGenerator/Discovery/MemberDiscovery.cs index d590814790..76a027e21c 100644 --- a/TUnit.Mocks.SourceGenerator/Discovery/MemberDiscovery.cs +++ b/TUnit.Mocks.SourceGenerator/Discovery/MemberDiscovery.cs @@ -75,7 +75,7 @@ public static (EquatableArray Methods, EquatableArray p.Type.GetFullyQualifiedName())); + var paramTypes = string.Join(',', indexer.Parameters.Select(p => p.Type.GetFullyQualifiedName())); var key = $"I:[{paramTypes}]"; if (seenProperties.TryGetValue(key, out var existingIndex)) { @@ -165,7 +165,7 @@ public static (EquatableArray Methods, EquatableArray p.Type.GetFullyQualifiedName())); + var paramTypes = string.Join(',', indexer.Parameters.Select(p => p.Type.GetFullyQualifiedName())); var key = $"I:[{paramTypes}]"; if (seenProperties.TryGetValue(key, out var existingIndex)) { @@ -524,7 +524,7 @@ private static string ComputeUnwrappedSmartDefault(ITypeSymbol returnType, bool private static string GetMethodKey(IMethodSymbol method) { - var paramTypes = string.Join(",", method.Parameters.Select(p => + var paramTypes = string.Join(',', method.Parameters.Select(p => p.Type.GetFullyQualifiedName() + (p.RefKind != RefKind.None ? "&" : ""))); var typeParams = method.TypeParameters.Length > 0 ? $"`{method.TypeParameters.Length}" : ""; return $"M:{method.Name}{typeParams}({paramTypes})"; diff --git a/TUnit.Mocks.SourceGenerator/Extensions/TypeSymbolExtensions.cs b/TUnit.Mocks.SourceGenerator/Extensions/TypeSymbolExtensions.cs index 8b719cfce4..8643508e76 100644 --- a/TUnit.Mocks.SourceGenerator/Extensions/TypeSymbolExtensions.cs +++ b/TUnit.Mocks.SourceGenerator/Extensions/TypeSymbolExtensions.cs @@ -118,13 +118,13 @@ private static string GetMemberKey(ISymbol member) { if (member is IMethodSymbol method) { - var paramTypes = string.Join(",", method.Parameters.Select(p => p.Type.GetFullyQualifiedName() + (p.RefKind != RefKind.None ? "&" : ""))); + var paramTypes = string.Join(',', method.Parameters.Select(p => p.Type.GetFullyQualifiedName() + (p.RefKind != RefKind.None ? "&" : ""))); var typeParams = method.TypeParameters.Length > 0 ? $"`{method.TypeParameters.Length}" : ""; return $"M:{method.Name}{typeParams}({paramTypes})"; } if (member is IPropertySymbol prop) { - var paramTypes = string.Join(",", prop.Parameters.Select(p => p.Type.GetFullyQualifiedName())); + var paramTypes = string.Join(',', prop.Parameters.Select(p => p.Type.GetFullyQualifiedName())); return prop.Parameters.Length > 0 ? $"P:{prop.Name}[{paramTypes}]" : $"P:{prop.Name}"; } if (member is IEventSymbol evt) diff --git a/TUnit.Mocks/Mock.cs b/TUnit.Mocks/Mock.cs index 2a8b23c6ce..ac440d5667 100644 --- a/TUnit.Mocks/Mock.cs +++ b/TUnit.Mocks/Mock.cs @@ -237,7 +237,7 @@ public static bool TryCreateAutoMock(Type type, MockBehavior behavior, out IMock private static string GetMultiKey(params Type[] types) { - return string.Join("|", types.Select(t => t.FullName ?? t.ToString())); + return string.Join('|', types.Select(t => t.FullName ?? t.ToString())); } ///