diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index b6de25849..15cc274c7 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -508,6 +508,7 @@ namespace ICSharpCode.Decompiler.CSharp typeSystemAstBuilder.SupportInitAccessors = settings.InitAccessors; typeSystemAstBuilder.SupportRecordClasses = settings.RecordClasses; typeSystemAstBuilder.SupportRecordStructs = settings.RecordStructs; + typeSystemAstBuilder.AlwaysUseGlobal = settings.AlwaysUseGlobal; return typeSystemAstBuilder; } diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index b278907bf..0c167800b 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -100,6 +100,7 @@ namespace ICSharpCode.Decompiler.CSharp this.astBuilder.AddResolveResultAnnotations = true; this.astBuilder.ShowAttributes = true; this.astBuilder.UseNullableSpecifierForValueTypes = settings.LiftNullables; + this.astBuilder.AlwaysUseGlobal = settings.AlwaysUseGlobal; this.typeInference = new TypeInference(compilation) { Algorithm = TypeInferenceAlgorithm.Improved }; } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs index 995164b3f..3b57da652 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs @@ -224,6 +224,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax /// Controls whether C# 10 "record" struct types are supported. /// public bool SupportRecordStructs { get; set; } + + /// + /// Controls whether all fully qualified type names should be prefixed with "global::". + /// + public bool AlwaysUseGlobal { get; set; } #endregion #region Convert Type @@ -535,7 +540,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax else { result.Target = ConvertNamespace(genericType.Namespace, - out _, genericType.Namespace == genericType.Name); + out _, AlwaysUseGlobal || genericType.Namespace == genericType.Name); } } result.MemberName = genericType.Name; diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs index 8ae658ae7..a5a11344d 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs @@ -170,6 +170,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms return new TypeSystemAstBuilder(resolver) { UseNullableSpecifierForValueTypes = settings.LiftNullables, + AlwaysUseGlobal = settings.AlwaysUseGlobal, AddResolveResultAnnotations = true, UseAliases = true }; diff --git a/ICSharpCode.Decompiler/DecompilerSettings.cs b/ICSharpCode.Decompiler/DecompilerSettings.cs index ec0f14f7c..d00f198f0 100644 --- a/ICSharpCode.Decompiler/DecompilerSettings.cs +++ b/ICSharpCode.Decompiler/DecompilerSettings.cs @@ -1915,6 +1915,24 @@ namespace ICSharpCode.Decompiler } } + bool alwaysUseGlobal = false; + + /// + /// Always fully qualify namespaces using the "global::" prefix. + /// + [Category("DecompilerSettings.Other")] + [Description("DecompilerSettings.AlwaysUseGlobal")] + public bool AlwaysUseGlobal { + get { return alwaysUseGlobal; } + set { + if (alwaysUseGlobal != value) + { + alwaysUseGlobal = value; + OnPropertyChanged(); + } + } + } + CSharpFormattingOptions csharpFormattingOptions; [Browsable(false)] diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index 5f59ad82c..001a03ea7 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -119,7 +119,7 @@ - + powershell -NoProfile -ExecutionPolicy Bypass -File BuildTools/sort-resx.ps1 diff --git a/ILSpy/Properties/Resources.Designer.cs b/ILSpy/Properties/Resources.Designer.cs index 2394d593c..a90649709 100644 --- a/ILSpy/Properties/Resources.Designer.cs +++ b/ILSpy/Properties/Resources.Designer.cs @@ -738,6 +738,15 @@ namespace ICSharpCode.ILSpy.Properties { } } + /// + /// Looks up a localized string similar to Always fully qualify namespaces using the "global::" prefix. + /// + public static string DecompilerSettings_AlwaysUseGlobal { + get { + return ResourceManager.GetString("DecompilerSettings.AlwaysUseGlobal", resourceCulture); + } + } + /// /// Looks up a localized string similar to Apply Windows Runtime projections on loaded assemblies. /// diff --git a/ILSpy/Properties/Resources.resx b/ILSpy/Properties/Resources.resx index a446434e6..a3b47c1e2 100644 --- a/ILSpy/Properties/Resources.resx +++ b/ILSpy/Properties/Resources.resx @@ -270,6 +270,9 @@ Are you sure you want to continue? Always use braces + + Always fully qualify namespaces using the "global::" prefix + Apply Windows Runtime projections on loaded assemblies