Browse Source

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

pull/2762/head
hexafluoride 3 years ago committed by Siegfried Pammer
parent
commit
fc6ae4c645
  1. 1
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 1
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  3. 7
      ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs
  4. 1
      ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs
  5. 18
      ICSharpCode.Decompiler/DecompilerSettings.cs

1
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -508,6 +508,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -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;
}

1
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -100,6 +100,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -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 };
}

7
ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

@ -224,6 +224,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -224,6 +224,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// 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
@ -535,7 +540,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -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;

1
ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs

@ -170,6 +170,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -170,6 +170,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
return new TypeSystemAstBuilder(resolver) {
UseNullableSpecifierForValueTypes = settings.LiftNullables,
AlwaysUseGlobal = settings.AlwaysUseGlobal,
AddResolveResultAnnotations = true,
UseAliases = true
};

18
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -1915,6 +1915,24 @@ namespace ICSharpCode.Decompiler @@ -1915,6 +1915,24 @@ namespace ICSharpCode.Decompiler
}
}
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)]

Loading…
Cancel
Save