Browse Source

Add option for `string.Concat` decompilation.

pull/2176/head
Daniel Grunwald 5 years ago
parent
commit
6bcb26db70
  1. 5
      ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs
  2. 18
      ICSharpCode.Decompiler/DecompilerSettings.cs
  3. 9
      ILSpy/Properties/Resources.Designer.cs
  4. 3
      ILSpy/Properties/Resources.resx

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

@ -16,11 +16,8 @@ @@ -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 @@ -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<LambdaExpression>().Any(
lambda => lambda.Annotation<IL.ILFunction>()?.Kind == IL.ILFunctionKind.ExpressionTree);

18
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -443,6 +443,24 @@ namespace ICSharpCode.Decompiler @@ -443,6 +443,24 @@ namespace ICSharpCode.Decompiler
}
}
bool stringConcat = true;
/// <summary>
/// Decompile 'string.Concat(a, b)' calls into 'a + b'.
/// </summary>
[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;
/// <summary>

9
ILSpy/Properties/Resources.Designer.cs generated

@ -1118,6 +1118,15 @@ namespace ICSharpCode.ILSpy.Properties { @@ -1118,6 +1118,15 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Decompile &apos;string.Concat(a, b)&apos; calls into &apos;a + b&apos;.
/// </summary>
public static string DecompilerSettings_StringConcat {
get {
return ResourceManager.GetString("DecompilerSettings.StringConcat", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Switch expressions.
/// </summary>

3
ILSpy/Properties/Resources.resx

@ -402,6 +402,9 @@ Are you sure you want to continue?</value> @@ -402,6 +402,9 @@ Are you sure you want to continue?</value>
<data name="DecompilerSettings.SparseIntegerSwitch" xml:space="preserve">
<value>Detect switch on integer even if IL code does not use a jump table</value>
</data>
<data name="DecompilerSettings.StringConcat" xml:space="preserve">
<value>Decompile 'string.Concat(a, b)' calls into 'a + b'</value>
</data>
<data name="DecompilerSettings.SwitchExpressions" xml:space="preserve">
<value>Switch expressions</value>
</data>

Loading…
Cancel
Save