Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<Compile Include="TestCases\ILPretty\Issue3442.cs" />
<Compile Include="TestCases\ILPretty\Issue3466.cs" />
<Compile Include="TestCases\ILPretty\Issue3524.cs" />
<Compile Include="TestCases\Pretty\ExpandParamsArgumentsDisabled.cs" />
<Compile Include="TestCases\Pretty\ExtensionProperties.cs" />
<None Include="TestCases\ILPretty\Issue3504.cs" />
<Compile Include="TestCases\ILPretty\MonoFixed.cs" />
Expand Down
6 changes: 6 additions & 0 deletions ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,12 @@ public async Task ParamsCollections([ValueSource(nameof(roslyn4OrNewerOptions))]
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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
public class ExpandParamsArgumentsDisabled
{
public void Test()
{
MethodWithParams(Array.Empty<int>());
MethodWithParams(new int[1] { 5 });
}

public void MethodWithParams(params int[] b)
{
}
}
}
2 changes: 1 addition & 1 deletion ICSharpCode.Decompiler/CSharp/CallBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ private ArgumentList BuildArgumentList(ExpectedTargetDetails expectedTargetDetai
{
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.
Expand Down
19 changes: 19 additions & 0 deletions ICSharpCode.Decompiler/DecompilerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,25 @@ public bool OptionalArguments {
}
}

bool expandParamsArguments = true;

/// <summary>
/// Gets/Sets whether to expand <c>params</c> arguments by replacing explicit array creation
/// with individual values in method calls.
/// </summary>
[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;

/// <summary>
Expand Down
9 changes: 9 additions & 0 deletions ILSpy/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ILSpy/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ Are you sure you want to continue?</value>
<data name="DecompilerSettings.DoWhileStatement" xml:space="preserve">
<value>Transform to do-while, if possible</value>
</data>
<data name="DecompilerSettings.ExpandParamsArguments" xml:space="preserve">
<value>Expand params arguments by removing explicit array creation</value>
</data>
<data name="DecompilerSettings.FSpecificOptions" xml:space="preserve">
<value>F#-specific options</value>
</data>
Expand Down
Loading