Browse Source

Add ExpandParamsArguments DecompilerSettings

pull/3534/head
Maximilian Schmöcker 5 months ago
parent
commit
43bfaba7e0
No known key found for this signature in database
GPG Key ID: 9B984776B4651E76
  1. 1
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 6
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  3. 17
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExpandParamsArgumentsDisabled.cs
  4. 2
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs
  5. 19
      ICSharpCode.Decompiler/DecompilerSettings.cs
  6. 9
      ILSpy/Properties/Resources.Designer.cs
  7. 3
      ILSpy/Properties/Resources.resx

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

@ -146,6 +146,7 @@
<Compile Include="TestCases\ILPretty\Issue3442.cs" /> <Compile Include="TestCases\ILPretty\Issue3442.cs" />
<Compile Include="TestCases\ILPretty\Issue3466.cs" /> <Compile Include="TestCases\ILPretty\Issue3466.cs" />
<Compile Include="TestCases\ILPretty\Issue3524.cs" /> <Compile Include="TestCases\ILPretty\Issue3524.cs" />
<Compile Include="TestCases\Pretty\ExpandParamsArgumentsDisabled.cs" />
<Compile Include="TestCases\Pretty\ExtensionProperties.cs" /> <Compile Include="TestCases\Pretty\ExtensionProperties.cs" />
<None Include="TestCases\ILPretty\Issue3504.cs" /> <None Include="TestCases\ILPretty\Issue3504.cs" />
<Compile Include="TestCases\ILPretty\MonoFixed.cs" /> <Compile Include="TestCases\ILPretty\MonoFixed.cs" />

6
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -617,6 +617,12 @@ namespace ICSharpCode.Decompiler.Tests
await RunForLibrary(cscOptions: cscOptions); await RunForLibrary(cscOptions: cscOptions);
} }
[Test]
public async Task ExpandParamsArgumentsDisabled([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
{
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => settings.ExpandParamsArguments = false);
}
[Test] [Test]
public async Task Issue1080([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions) public async Task Issue1080([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions)
{ {

17
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<int>());
MethodWithParams(new int[1] { 5 });
}
public void MethodWithParams(params int[] b)
{
}
}
}

2
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -969,7 +969,7 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
firstOptionalArgumentIndex = -2; 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 // Parameter is marked params
// If the argument is an array creation, inline all elements into the call and add missing default values. // If the argument is an array creation, inline all elements into the call and add missing default values.

19
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -1703,6 +1703,25 @@ namespace ICSharpCode.Decompiler
} }
} }
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; bool localFunctions = true;
/// <summary> /// <summary>

9
ILSpy/Properties/Resources.Designer.cs generated

@ -1017,6 +1017,15 @@ namespace ICSharpCode.ILSpy.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Expand params arguments by removing explicit array creation.
/// </summary>
public static string DecompilerSettings_ExpandParamsArguments {
get {
return ResourceManager.GetString("DecompilerSettings.ExpandParamsArguments", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Use file-scoped namespace declarations. /// Looks up a localized string similar to Use file-scoped namespace declarations.
/// </summary> /// </summary>

3
ILSpy/Properties/Resources.resx

@ -360,6 +360,9 @@ Are you sure you want to continue?</value>
<data name="DecompilerSettings.DoWhileStatement" xml:space="preserve"> <data name="DecompilerSettings.DoWhileStatement" xml:space="preserve">
<value>Transform to do-while, if possible</value> <value>Transform to do-while, if possible</value>
</data> </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"> <data name="DecompilerSettings.FSpecificOptions" xml:space="preserve">
<value>F#-specific options</value> <value>F#-specific options</value>
</data> </data>

Loading…
Cancel
Save