diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs b/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs index 090b182e1..1ccc7fdd1 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs @@ -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; diff --git a/ICSharpCode.Decompiler/DecompilerSettings.cs b/ICSharpCode.Decompiler/DecompilerSettings.cs index 1b8684d99..00c158d54 100644 --- a/ICSharpCode.Decompiler/DecompilerSettings.cs +++ b/ICSharpCode.Decompiler/DecompilerSettings.cs @@ -2274,6 +2274,27 @@ namespace ICSharpCode.Decompiler } } + bool alwaysMoveInitializer = false; + + /// + /// 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. + /// + [Category("DecompilerSettings.Other")] + [Description("DecompilerSettings.AlwaysMoveInitializer")] + public bool AlwaysMoveInitializer { + get { return alwaysMoveInitializer; } + set { + if (alwaysMoveInitializer != value) + { + alwaysMoveInitializer = value; + OnPropertyChanged(); + } + } + } + bool sortCustomAttributes = false; /// diff --git a/ILSpy/Properties/Resources.Designer.cs b/ILSpy/Properties/Resources.Designer.cs index 6c08ae8e7..22e5cf2dc 100644 --- a/ILSpy/Properties/Resources.Designer.cs +++ b/ILSpy/Properties/Resources.Designer.cs @@ -729,6 +729,15 @@ namespace ICSharpCode.ILSpy.Properties { } } + /// + /// Looks up a localized string similar to Always move field initializers from constructors to declarations. + /// + public static string DecompilerSettings_AlwaysMoveInitializer { + get { + return ResourceManager.GetString("DecompilerSettings.AlwaysMoveInitializer", resourceCulture); + } + } + /// /// Looks up a localized string similar to Always qualify member references. /// @@ -1838,20 +1847,20 @@ namespace ICSharpCode.ILSpy.Properties { return ResourceManager.GetString("ExpandUsingDeclarationsAfterDecompilation", resourceCulture); } } - - /// - /// Looks up a localized string similar to Extract all package entries. - /// - public static string ExtractAllPackageEntries { - get { - return ResourceManager.GetString("ExtractAllPackageEntries", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Extract package entry. - /// - public static string ExtractPackageEntry { + + /// + /// Looks up a localized string similar to Extract all package entries. + /// + public static string ExtractAllPackageEntries { + get { + return ResourceManager.GetString("ExtractAllPackageEntries", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Extract package entry. + /// + public static string ExtractPackageEntry { get { return ResourceManager.GetString("ExtractPackageEntry", resourceCulture); } diff --git a/ILSpy/Properties/Resources.resx b/ILSpy/Properties/Resources.resx index f14786326..bb0d12dde 100644 --- a/ILSpy/Properties/Resources.resx +++ b/ILSpy/Properties/Resources.resx @@ -264,6 +264,9 @@ Are you sure you want to continue? Always cast targets of explicit interface implementation calls + + Always move field initializers from constructors to declarations + Always qualify member references @@ -361,7 +364,7 @@ Are you sure you want to continue? Transform to do-while, if possible - Expand params arguments by removing explicit array creation + Expand params arguments by removing explicit array creation F#-specific options diff --git a/ILSpy/Properties/Resources.zh-Hans.resx b/ILSpy/Properties/Resources.zh-Hans.resx index bbdc942ce..d61d8f79e 100644 --- a/ILSpy/Properties/Resources.zh-Hans.resx +++ b/ILSpy/Properties/Resources.zh-Hans.resx @@ -258,6 +258,9 @@ 始终强制转换显式接口实现调用的目标 + + + 始终限定成员引用