Browse Source

Fix #1567: Do not transform string.Concat method calls to + operators if named arguments are used.

pull/1596/head
Siegfried Pammer 6 years ago
parent
commit
e99bc2b145
  1. 10
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.cs
  2. 12
      ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs

10
ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.cs

@ -97,6 +97,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -97,6 +97,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
};
}
private static string GetStr(int unused)
{
return " ";
}
public static string Issue1567(string str1, string str2)
{
return string.Concat(str1.Replace('"', '\''), str2: str2.Replace('"', '\''), str1: GetStr(42));
}
private void CallerMemberName([CallerMemberName] string memberName = null)
{

12
ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs

@ -154,8 +154,16 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -154,8 +154,16 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
if (arguments.Length < 2)
return false;
return arguments[0].GetResolveResult().Type.IsKnownType(KnownTypeCode.String) ||
arguments[1].GetResolveResult().Type.IsKnownType(KnownTypeCode.String);
bool valid = false;
foreach (var argument in arguments) {
if (argument is NamedArgumentExpression)
return false;
if (argument.GetResolveResult().Type.IsKnownType(KnownTypeCode.String))
valid = true;
}
return valid;
}
static BinaryOperatorType? GetBinaryOperatorTypeFromMetadataName(string name)

Loading…
Cancel
Save