diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
index 0282f9d00..2851e3eea 100644
--- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
+++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
@@ -146,6 +146,7 @@
+
diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
index d67877e72..d28edc76a 100644
--- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
+++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
@@ -617,6 +617,12 @@ namespace ICSharpCode.Decompiler.Tests
await RunForLibrary(cscOptions: cscOptions);
}
+ [Test]
+ public async Task ExpandParamsArgumentsDisabled([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
+ {
+ await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => settings.ExpandParamsArguments = false);
+ }
+
[Test]
public async Task Issue1080([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions)
{
diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpandParamsArgumentsDisabled.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpandParamsArgumentsDisabled.cs
new file mode 100644
index 000000000..86d168df6
--- /dev/null
+++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpandParamsArgumentsDisabled.cs
@@ -0,0 +1,17 @@
+using System;
+
+namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
+{
+ public class ExpandParamsArgumentsDisabled
+ {
+ public void Test()
+ {
+ MethodWithParams(Array.Empty());
+ MethodWithParams(new int[1] { 5 });
+ }
+
+ public void MethodWithParams(params int[] b)
+ {
+ }
+ }
+}
diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs
index 2ff1ce4d1..f4fa1fb03 100644
--- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs
+++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs
@@ -969,7 +969,7 @@ namespace ICSharpCode.Decompiler.CSharp
{
firstOptionalArgumentIndex = -2;
}
- if (parameter.IsParams && i + 1 == callArguments.Count && argumentToParameterMap == null)
+ if (expressionBuilder.settings.ExpandParamsArguments && parameter.IsParams && i + 1 == callArguments.Count && argumentToParameterMap == null)
{
// Parameter is marked params
// If the argument is an array creation, inline all elements into the call and add missing default values.
diff --git a/ICSharpCode.Decompiler/DecompilerSettings.cs b/ICSharpCode.Decompiler/DecompilerSettings.cs
index 0abb9a2fb..1b8684d99 100644
--- a/ICSharpCode.Decompiler/DecompilerSettings.cs
+++ b/ICSharpCode.Decompiler/DecompilerSettings.cs
@@ -1703,6 +1703,25 @@ namespace ICSharpCode.Decompiler
}
}
+ bool expandParamsArguments = true;
+
+ ///
+ /// Gets/Sets whether to expand params arguments by replacing explicit array creation
+ /// with individual values in method calls.
+ ///
+ [Category("C# 1.0 / VS .NET")]
+ [Description("DecompilerSettings.ExpandParamsArguments")]
+ public bool ExpandParamsArguments {
+ get { return expandParamsArguments; }
+ set {
+ if (expandParamsArguments != value)
+ {
+ expandParamsArguments = value;
+ OnPropertyChanged();
+ }
+ }
+ }
+
bool localFunctions = true;
///
diff --git a/ILSpy/Properties/Resources.Designer.cs b/ILSpy/Properties/Resources.Designer.cs
index e6308d83e..6c08ae8e7 100644
--- a/ILSpy/Properties/Resources.Designer.cs
+++ b/ILSpy/Properties/Resources.Designer.cs
@@ -1017,6 +1017,15 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to Expand params arguments by removing explicit array creation.
+ ///
+ public static string DecompilerSettings_ExpandParamsArguments {
+ get {
+ return ResourceManager.GetString("DecompilerSettings.ExpandParamsArguments", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Use file-scoped namespace declarations.
///
diff --git a/ILSpy/Properties/Resources.resx b/ILSpy/Properties/Resources.resx
index 65d7471aa..f14786326 100644
--- a/ILSpy/Properties/Resources.resx
+++ b/ILSpy/Properties/Resources.resx
@@ -360,6 +360,9 @@ Are you sure you want to continue?
Transform to do-while, if possible
+
+ Expand params arguments by removing explicit array creation
+
F#-specific options