Browse Source

#1999: Add EscapeInvalidIdentifiers flag to allow the use of the EscapeInvalidIdentifiers transform when writing files to disk. We still show the unescaped identifiers in the ILSpy UI.

pull/2016/head
Siegfried Pammer 5 years ago
parent
commit
84a7c968c6
  1. 6
      ILSpy/DecompilationOptions.cs
  2. 6
      ILSpy/Languages/CSharpLanguage.cs
  3. 1
      ILSpy/TextView/DecompilerTextView.cs

6
ILSpy/DecompilationOptions.cs

@ -37,6 +37,12 @@ namespace ICSharpCode.ILSpy @@ -37,6 +37,12 @@ namespace ICSharpCode.ILSpy
/// Gets/Sets the directory into which the project is saved.
/// </summary>
public string SaveAsProjectDirectory { get; set; }
/// <summary>
/// Gets/sets whether invalid identifiers should be escaped (and therefore the code be made compilable).
/// This setting is ignored in case <see cref="SaveAsProjectDirectory"/> is set.
/// </summary>
public bool EscapeInvalidIdentifiers { get; set; }
/// <summary>
/// Gets the cancellation token that is used to abort the decompiler.

6
ILSpy/Languages/CSharpLanguage.cs

@ -119,6 +119,9 @@ namespace ICSharpCode.ILSpy @@ -119,6 +119,9 @@ namespace ICSharpCode.ILSpy
decompiler.DebugInfoProvider = module.GetDebugInfoOrNull();
while (decompiler.AstTransforms.Count > transformCount)
decompiler.AstTransforms.RemoveAt(decompiler.AstTransforms.Count - 1);
if (options.EscapeInvalidIdentifiers) {
decompiler.AstTransforms.Add(new EscapeInvalidIdentifiers());
}
return decompiler;
}
@ -413,6 +416,9 @@ namespace ICSharpCode.ILSpy @@ -413,6 +416,9 @@ namespace ICSharpCode.ILSpy
CSharpDecompiler decompiler = new CSharpDecompiler(typeSystem, options.DecompilerSettings);
decompiler.CancellationToken = options.CancellationToken;
if (options.EscapeInvalidIdentifiers) {
decompiler.AstTransforms.Add(new EscapeInvalidIdentifiers());
}
SyntaxTree st;
if (options.FullDecompilation) {
st = decompiler.DecompileWholeModuleAsSingleFile();

1
ILSpy/TextView/DecompilerTextView.cs

@ -952,6 +952,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -952,6 +952,7 @@ namespace ICSharpCode.ILSpy.TextView
Thread thread = new Thread(new ThreadStart(
delegate {
try {
context.Options.EscapeInvalidIdentifiers = true;
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (StreamWriter w = new StreamWriter(fileName)) {

Loading…
Cancel
Save