Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to always fully qualify type names with global:: #2762

Merged
merged 3 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,24 @@ public bool AggressiveInlining {
}
}

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
2 changes: 1 addition & 1 deletion ILSpy/ILSpy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
<SortResXStamp Include="obj\sort-resx.stamp" />
</ItemGroup>

<Target Name="SortResX" BeforeTargets="BeforeBuild" Inputs="@(SortResXInput)" Outputs="@(SortResXStamp)">
<Target Name="SortResX" BeforeTargets="BeforeBuild" Inputs="@(SortResXInput)" Outputs="@(SortResXStamp)" Condition="'$(GITHUB_ACTIONS)' != 'true'">
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<SortResX>powershell -NoProfile -ExecutionPolicy Bypass -File BuildTools/sort-resx.ps1</SortResX>
</PropertyGroup>
Expand Down
9 changes: 9 additions & 0 deletions ILSpy/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ILSpy/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ Are you sure you want to continue?</value>
<data name="DecompilerSettings.AlwaysUseBraces" xml:space="preserve">
<value>Always use braces</value>
</data>
<data name="DecompilerSettings.AlwaysUseGlobal" xml:space="preserve">
<value>Always fully qualify namespaces using the "global::" prefix</value>
</data>
<data name="DecompilerSettings.ApplyWindowsRuntimeProjectionsOnLoadedAssemblies" xml:space="preserve">
<value>Apply Windows Runtime projections on loaded assemblies</value>
</data>
Expand Down