Browse Source

Merge pull request #3540 from miloush/AlwaysMoveInitializer

Always move initializer decompilation setting
null-coalescing-assignment
Siegfried Pammer 5 months ago committed by GitHub
parent
commit
0c2b001a95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs
  2. 21
      ICSharpCode.Decompiler/DecompilerSettings.cs
  3. 37
      ILSpy/Properties/Resources.Designer.cs
  4. 5
      ILSpy/Properties/Resources.resx
  5. 3
      ILSpy/Properties/Resources.zh-Hans.resx

2
ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs

@ -350,7 +350,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -350,7 +350,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
if (!(fieldOrProperty is IField || fieldOrProperty is IProperty) || !fieldOrProperty.IsStatic)
break;
// Only move fields that are constants, if the declaring type is not marked beforefieldinit.
if (!declaringTypeIsBeforeFieldInit && fieldOrProperty is not IField { IsConst: true })
if (!context.Settings.AlwaysMoveInitializer && !declaringTypeIsBeforeFieldInit && fieldOrProperty is not IField { IsConst: true })
{
pos++;
continue;

21
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -2274,6 +2274,27 @@ namespace ICSharpCode.Decompiler @@ -2274,6 +2274,27 @@ namespace ICSharpCode.Decompiler
}
}
bool alwaysMoveInitializer = false;
/// <summary>
/// If set to false (the default), the decompiler will move field initializers at the start of constructors
/// to their respective field declrations (TransformFieldAndConstructorInitializers) only when the declaring
/// type has BeforeFieldInit or the member IsConst.
/// If set true, the decompiler will always move them regardless of the flags.
/// </summary>
[Category("DecompilerSettings.Other")]
[Description("DecompilerSettings.AlwaysMoveInitializer")]
public bool AlwaysMoveInitializer {
get { return alwaysMoveInitializer; }
set {
if (alwaysMoveInitializer != value)
{
alwaysMoveInitializer = value;
OnPropertyChanged();
}
}
}
bool sortCustomAttributes = false;
/// <summary>

37
ILSpy/Properties/Resources.Designer.cs generated

@ -729,6 +729,15 @@ namespace ICSharpCode.ILSpy.Properties { @@ -729,6 +729,15 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Always move field initializers from constructors to declarations.
/// </summary>
public static string DecompilerSettings_AlwaysMoveInitializer {
get {
return ResourceManager.GetString("DecompilerSettings.AlwaysMoveInitializer", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Always qualify member references.
/// </summary>
@ -1838,20 +1847,20 @@ namespace ICSharpCode.ILSpy.Properties { @@ -1838,20 +1847,20 @@ namespace ICSharpCode.ILSpy.Properties {
return ResourceManager.GetString("ExpandUsingDeclarationsAfterDecompilation", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Extract all package entries.
/// </summary>
public static string ExtractAllPackageEntries {
get {
return ResourceManager.GetString("ExtractAllPackageEntries", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Extract package entry.
/// </summary>
public static string ExtractPackageEntry {
/// <summary>
/// Looks up a localized string similar to Extract all package entries.
/// </summary>
public static string ExtractAllPackageEntries {
get {
return ResourceManager.GetString("ExtractAllPackageEntries", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Extract package entry.
/// </summary>
public static string ExtractPackageEntry {
get {
return ResourceManager.GetString("ExtractPackageEntry", resourceCulture);
}

5
ILSpy/Properties/Resources.resx

@ -264,6 +264,9 @@ Are you sure you want to continue?</value> @@ -264,6 +264,9 @@ Are you sure you want to continue?</value>
<data name="DecompilerSettings.AlwaysCastTargetsOfExplicitInterfaceImplementationCalls" xml:space="preserve">
<value>Always cast targets of explicit interface implementation calls</value>
</data>
<data name="DecompilerSettings.AlwaysMoveInitializer" xml:space="preserve">
<value>Always move field initializers from constructors to declarations</value>
</data>
<data name="DecompilerSettings.AlwaysQualifyMemberReferences" xml:space="preserve">
<value>Always qualify member references</value>
</data>
@ -361,7 +364,7 @@ Are you sure you want to continue?</value> @@ -361,7 +364,7 @@ Are you sure you want to continue?</value>
<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>
<value>Expand params arguments by removing explicit array creation</value>
</data>
<data name="DecompilerSettings.FSpecificOptions" xml:space="preserve">
<value>F#-specific options</value>

3
ILSpy/Properties/Resources.zh-Hans.resx

@ -258,6 +258,9 @@ @@ -258,6 +258,9 @@
<data name="DecompilerSettings.AlwaysCastTargetsOfExplicitInterfaceImplementationCalls" xml:space="preserve">
<value>始终强制转换显式接口实现调用的目标</value>
</data>
<data name="DecompilerSettings.AlwaysMoveInitializer" xml:space="preserve">
<value />
</data>
<data name="DecompilerSettings.AlwaysQualifyMemberReferences" xml:space="preserve">
<value>始终限定成员引用</value>
</data>

Loading…
Cancel
Save