diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs b/ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs index f9680a498..f2f7a355f 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs @@ -16,11 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; -using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Text; using ICSharpCode.Decompiler.CSharp.Syntax; using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; @@ -59,7 +56,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms var arguments = invocationExpression.Arguments.ToArray(); // Reduce "String.Concat(a, b)" to "a + b" - if (IsStringConcat(method) && CheckArgumentsForStringConcat(arguments)) + if (IsStringConcat(method) && context.Settings.StringConcat && CheckArgumentsForStringConcat(arguments)) { bool isInExpressionTree = invocationExpression.Ancestors.OfType().Any( lambda => lambda.Annotation()?.Kind == IL.ILFunctionKind.ExpressionTree); diff --git a/ICSharpCode.Decompiler/DecompilerSettings.cs b/ICSharpCode.Decompiler/DecompilerSettings.cs index bfac69635..b7e714035 100644 --- a/ICSharpCode.Decompiler/DecompilerSettings.cs +++ b/ICSharpCode.Decompiler/DecompilerSettings.cs @@ -443,6 +443,24 @@ namespace ICSharpCode.Decompiler } } + bool stringConcat = true; + + /// + /// Decompile 'string.Concat(a, b)' calls into 'a + b'. + /// + [Category("C# 1.0 / VS .NET")] + [Description("DecompilerSettings.StringConcat")] + public bool StringConcat { + get { return stringConcat; } + set { + if (stringConcat != value) + { + stringConcat = value; + OnPropertyChanged(); + } + } + } + bool liftNullables = true; /// diff --git a/ILSpy/Properties/Resources.Designer.cs b/ILSpy/Properties/Resources.Designer.cs index 43bd69c5f..c46b294d8 100644 --- a/ILSpy/Properties/Resources.Designer.cs +++ b/ILSpy/Properties/Resources.Designer.cs @@ -1118,6 +1118,15 @@ namespace ICSharpCode.ILSpy.Properties { } } + /// + /// Looks up a localized string similar to Decompile 'string.Concat(a, b)' calls into 'a + b'. + /// + public static string DecompilerSettings_StringConcat { + get { + return ResourceManager.GetString("DecompilerSettings.StringConcat", resourceCulture); + } + } + /// /// Looks up a localized string similar to Switch expressions. /// diff --git a/ILSpy/Properties/Resources.resx b/ILSpy/Properties/Resources.resx index d1d5b6c30..be0899451 100644 --- a/ILSpy/Properties/Resources.resx +++ b/ILSpy/Properties/Resources.resx @@ -402,6 +402,9 @@ Are you sure you want to continue? Detect switch on integer even if IL code does not use a jump table + + Decompile 'string.Concat(a, b)' calls into 'a + b' + Switch expressions