Skip to content

Commit 7f58490

Browse files
authored
Merge pull request #3534 from MSchmoecker/feat-expand-params-option
Add ExpandParamsArguments DecompilerSettings
2 parents e3b1eb8 + 43bfaba commit 7f58490

File tree

7 files changed

+56
-1
lines changed

7 files changed

+56
-1
lines changed

ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
<Compile Include="TestCases\ILPretty\Issue3442.cs" />
147147
<Compile Include="TestCases\ILPretty\Issue3466.cs" />
148148
<Compile Include="TestCases\ILPretty\Issue3524.cs" />
149+
<Compile Include="TestCases\Pretty\ExpandParamsArgumentsDisabled.cs" />
149150
<Compile Include="TestCases\Pretty\ExtensionProperties.cs" />
150151
<None Include="TestCases\ILPretty\Issue3504.cs" />
151152
<Compile Include="TestCases\ILPretty\MonoFixed.cs" />

ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,12 @@ public async Task ParamsCollections([ValueSource(nameof(roslyn4OrNewerOptions))]
617617
await RunForLibrary(cscOptions: cscOptions);
618618
}
619619

620+
[Test]
621+
public async Task ExpandParamsArgumentsDisabled([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
622+
{
623+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => settings.ExpandParamsArguments = false);
624+
}
625+
620626
[Test]
621627
public async Task Issue1080([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions)
622628
{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
4+
{
5+
public class ExpandParamsArgumentsDisabled
6+
{
7+
public void Test()
8+
{
9+
MethodWithParams(Array.Empty<int>());
10+
MethodWithParams(new int[1] { 5 });
11+
}
12+
13+
public void MethodWithParams(params int[] b)
14+
{
15+
}
16+
}
17+
}

ICSharpCode.Decompiler/CSharp/CallBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ private ArgumentList BuildArgumentList(ExpectedTargetDetails expectedTargetDetai
969969
{
970970
firstOptionalArgumentIndex = -2;
971971
}
972-
if (parameter.IsParams && i + 1 == callArguments.Count && argumentToParameterMap == null)
972+
if (expressionBuilder.settings.ExpandParamsArguments && parameter.IsParams && i + 1 == callArguments.Count && argumentToParameterMap == null)
973973
{
974974
// Parameter is marked params
975975
// If the argument is an array creation, inline all elements into the call and add missing default values.

ICSharpCode.Decompiler/DecompilerSettings.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,25 @@ public bool OptionalArguments {
17031703
}
17041704
}
17051705

1706+
bool expandParamsArguments = true;
1707+
1708+
/// <summary>
1709+
/// Gets/Sets whether to expand <c>params</c> arguments by replacing explicit array creation
1710+
/// with individual values in method calls.
1711+
/// </summary>
1712+
[Category("C# 1.0 / VS .NET")]
1713+
[Description("DecompilerSettings.ExpandParamsArguments")]
1714+
public bool ExpandParamsArguments {
1715+
get { return expandParamsArguments; }
1716+
set {
1717+
if (expandParamsArguments != value)
1718+
{
1719+
expandParamsArguments = value;
1720+
OnPropertyChanged();
1721+
}
1722+
}
1723+
}
1724+
17061725
bool localFunctions = true;
17071726

17081727
/// <summary>

ILSpy/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ILSpy/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ Are you sure you want to continue?</value>
360360
<data name="DecompilerSettings.DoWhileStatement" xml:space="preserve">
361361
<value>Transform to do-while, if possible</value>
362362
</data>
363+
<data name="DecompilerSettings.ExpandParamsArguments" xml:space="preserve">
364+
<value>Expand params arguments by removing explicit array creation</value>
365+
</data>
363366
<data name="DecompilerSettings.FSpecificOptions" xml:space="preserve">
364367
<value>F#-specific options</value>
365368
</data>

0 commit comments

Comments
 (0)