Skip to content

Commit 36bd5ad

Browse files
Adjust string.Concat handling in ReplaceMethodCallsWithOperators to support unexpanded string.Concat calls.
1 parent efe8989 commit 36bd5ad

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,18 @@ void ProcessInvocationExpression(InvocationExpression invocationExpression)
5757
var arguments = invocationExpression.Arguments.ToArray();
5858

5959
// Reduce "String.Concat(a, b)" to "a + b"
60-
if (IsStringConcat(method) && context.Settings.StringConcat && CheckArgumentsForStringConcat(arguments))
60+
if (IsStringConcat(method) && context.Settings.StringConcat)
6161
{
62+
if (arguments is [ArrayCreateExpression ace] && method.Parameters is [{ Type: ArrayType }])
63+
{
64+
arguments = ace.Initializer.Elements.ToArray();
65+
}
66+
67+
if (!CheckArgumentsForStringConcat(arguments))
68+
{
69+
return;
70+
}
71+
6272
bool isInExpressionTree = invocationExpression.Ancestors.OfType<LambdaExpression>().Any(
6373
lambda => lambda.Annotation<IL.ILFunction>()?.Kind == IL.ILFunctionKind.ExpressionTree);
6474
Expression arg0 = arguments[0].Detach();

0 commit comments

Comments
 (0)