Skip to content

Commit

Permalink
Add option to always fully qualify type names with global::
Browse files Browse the repository at this point in the history
  • Loading branch information
hexafluoride committed Aug 8, 2022
1 parent a8f25c2 commit 6ecc48d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
Expand Up @@ -508,6 +508,7 @@ static TypeSystemAstBuilder CreateAstBuilder(DecompilerSettings settings)
typeSystemAstBuilder.SupportInitAccessors = settings.InitAccessors;
typeSystemAstBuilder.SupportRecordClasses = settings.RecordClasses;
typeSystemAstBuilder.SupportRecordStructs = settings.RecordStructs;
typeSystemAstBuilder.AlwaysUseGlobal = settings.AlwaysUseGlobal;
return typeSystemAstBuilder;
}

Expand Down
1 change: 1 addition & 0 deletions ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
Expand Up @@ -100,6 +100,7 @@ public ExpressionBuilder(StatementBuilder statementBuilder, IDecompilerTypeSyste
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 };
}

Expand Down
7 changes: 6 additions & 1 deletion ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs
Expand Up @@ -224,6 +224,11 @@ void InitProperties()
/// Controls whether C# 10 "record" struct types are supported.
/// </summary>
public bool SupportRecordStructs { get; set; }

/// <summary>
/// Controls whether all fully qualified type names should be prefixed with "global::".
/// </summary>
public bool AlwaysUseGlobal { get; set; }
#endregion

#region Convert Type
Expand Down Expand Up @@ -535,7 +540,7 @@ AstType ConvertTypeHelper(IType genericType, IReadOnlyList<IType> typeArguments)
else
{
result.Target = ConvertNamespace(genericType.Namespace,
out _, genericType.Namespace == genericType.Name);
out _, AlwaysUseGlobal || genericType.Namespace == genericType.Name);
}
}
result.MemberName = genericType.Name;
Expand Down
Expand Up @@ -170,6 +170,7 @@ TypeSystemAstBuilder CreateAstBuilder(CSharpTypeResolveContext context, IL.ILFun

return new TypeSystemAstBuilder(resolver) {
UseNullableSpecifierForValueTypes = settings.LiftNullables,
AlwaysUseGlobal = settings.AlwaysUseGlobal,
AddResolveResultAnnotations = true,
UseAliases = true
};
Expand Down
18 changes: 18 additions & 0 deletions ICSharpCode.Decompiler/DecompilerSettings.cs
Expand Up @@ -1915,6 +1915,24 @@ public CSharp.LanguageVersion GetMinimumRequiredVersion()
}
}

bool alwaysUseGlobal = false;

/// <summary>
/// Always fully qualify namespaces using the "global::" prefix.
/// </summary>
[Category("DecompilerSettings.Other")]
[Description("DecompilerSettings.AlwaysUseGlobal")]
public bool AlwaysUseGlobal {
get { return alwaysUseGlobal; }
set {
if (alwaysUseGlobal != value)
{
alwaysUseGlobal = value;
OnPropertyChanged();
}
}
}

CSharpFormattingOptions csharpFormattingOptions;

[Browsable(false)]
Expand Down

0 comments on commit 6ecc48d

Please sign in to comment.