diff --git a/ILSpy/DecompilationOptions.cs b/ILSpy/DecompilationOptions.cs index 840c1a5f4..b73bb8530 100644 --- a/ILSpy/DecompilationOptions.cs +++ b/ILSpy/DecompilationOptions.cs @@ -37,6 +37,12 @@ namespace ICSharpCode.ILSpy /// Gets/Sets the directory into which the project is saved. /// public string SaveAsProjectDirectory { get; set; } + + /// + /// Gets/sets whether invalid identifiers should be escaped (and therefore the code be made compilable). + /// This setting is ignored in case is set. + /// + public bool EscapeInvalidIdentifiers { get; set; } /// /// Gets the cancellation token that is used to abort the decompiler. diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index 8e68ea5f8..4f40c308d 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -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 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(); diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index 5f2f18344..354e0a4a8 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -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)) {