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)]