diff --git a/ICSharpCode.Decompiler/Output/ITextOutput.cs b/ICSharpCode.Decompiler/Output/ITextOutput.cs index 9c5ac0548..8187f182f 100644 --- a/ICSharpCode.Decompiler/Output/ITextOutput.cs +++ b/ICSharpCode.Decompiler/Output/ITextOutput.cs @@ -26,6 +26,7 @@ namespace ICSharpCode.Decompiler { public interface ITextOutput { + string IndentationString { get; set; } void Indent(); void Unindent(); void Write(char ch); diff --git a/ICSharpCode.Decompiler/Output/PlainTextOutput.cs b/ICSharpCode.Decompiler/Output/PlainTextOutput.cs index a2fcafa1b..14f4e4903 100644 --- a/ICSharpCode.Decompiler/Output/PlainTextOutput.cs +++ b/ICSharpCode.Decompiler/Output/PlainTextOutput.cs @@ -35,7 +35,9 @@ namespace ICSharpCode.Decompiler int line = 1; int column = 1; - + + public string IndentationString { get; set; } = "\t"; + public PlainTextOutput(TextWriter writer) { if (writer == null) @@ -74,7 +76,7 @@ namespace ICSharpCode.Decompiler if (needsIndent) { needsIndent = false; for (int i = 0; i < indent; i++) { - writer.Write('\t'); + writer.Write(IndentationString); } column += indent; } @@ -154,6 +156,15 @@ namespace ICSharpCode.Decompiler this.actions = new List>(); } + string ITextOutput.IndentationString { + get { + return target.IndentationString; + } + set { + target.IndentationString = value; + } + } + public void Commit() { foreach (var action in actions) { diff --git a/ILSpy/DecompilationOptions.cs b/ILSpy/DecompilationOptions.cs index 229e876b0..736ec2eb0 100644 --- a/ILSpy/DecompilationOptions.cs +++ b/ILSpy/DecompilationOptions.cs @@ -86,6 +86,17 @@ namespace ICSharpCode.ILSpy newSettings.ExpandUsingDeclarations = displaySettings.ExpandUsingDeclarations; newSettings.FoldBraces = displaySettings.FoldBraces; newSettings.ShowDebugInfo = displaySettings.ShowDebugInfo; + newSettings.CSharpFormattingOptions.IndentationString = GetIndentationString(displaySettings); + } + + private string GetIndentationString(DisplaySettings displaySettings) + { + if (displaySettings.IndentationUseTabs) { + int numberOfTabs = displaySettings.IndentationSize / displaySettings.IndentationTabSize; + int numberOfSpaces = displaySettings.IndentationSize % displaySettings.IndentationTabSize; + return new string('\t', numberOfTabs) + new string(' ', numberOfSpaces); + } + return new string(' ', displaySettings.IndentationSize); } } } diff --git a/ILSpy/Languages/CSharpILMixedLanguage.cs b/ILSpy/Languages/CSharpILMixedLanguage.cs index 855dd8b99..8b4858c75 100644 --- a/ILSpy/Languages/CSharpILMixedLanguage.cs +++ b/ILSpy/Languages/CSharpILMixedLanguage.cs @@ -65,7 +65,7 @@ namespace ICSharpCode.ILSpy static void WriteCode(TextWriter output, DecompilerSettings settings, SyntaxTree syntaxTree, IDecompilerTypeSystem typeSystem) { syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); - TokenWriter tokenWriter = new TextWriterTokenWriter(output); + TokenWriter tokenWriter = new TextWriterTokenWriter(output) { IndentationString = settings.CSharpFormattingOptions.IndentationString }; tokenWriter = TokenWriter.WrapInWriterThatSetsLocationsInAST(tokenWriter); syntaxTree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, settings.CSharpFormattingOptions)); } diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index 25b09f4f4..1d34d068b 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -121,6 +121,7 @@ namespace ICSharpCode.ILSpy void WriteCode(ITextOutput output, DecompilerSettings settings, SyntaxTree syntaxTree, IDecompilerTypeSystem typeSystem) { syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); + output.IndentationString = settings.CSharpFormattingOptions.IndentationString; TokenWriter tokenWriter = new TextTokenWriter(output, settings, typeSystem); if (output is ISmartTextOutput highlightingOutput) { tokenWriter = new CSharpHighlightingTokenWriter(tokenWriter, highlightingOutput); diff --git a/ILSpy/Languages/ILLanguage.cs b/ILSpy/Languages/ILLanguage.cs index 137548652..e2ab9d1f3 100644 --- a/ILSpy/Languages/ILLanguage.cs +++ b/ILSpy/Languages/ILLanguage.cs @@ -52,6 +52,7 @@ namespace ICSharpCode.ILSpy protected virtual ReflectionDisassembler CreateDisassembler(ITextOutput output, DecompilationOptions options) { + output.IndentationString = options.DecompilerSettings.CSharpFormattingOptions.IndentationString; return new ReflectionDisassembler(output, options.CancellationToken) { DetectControlStructure = detectControlStructure, ShowSequencePoints = options.DecompilerSettings.ShowDebugInfo, diff --git a/ILSpy/Options/DecompilerSettingsPanel.xaml b/ILSpy/Options/DecompilerSettingsPanel.xaml index d3f996603..c020084e3 100644 --- a/ILSpy/Options/DecompilerSettingsPanel.xaml +++ b/ILSpy/Options/DecompilerSettingsPanel.xaml @@ -18,7 +18,7 @@ - +