diff --git a/ICSharpCode.Decompiler/DecompilerSettings.cs b/ICSharpCode.Decompiler/DecompilerSettings.cs index 6e3f0da9b..378085fb1 100644 --- a/ICSharpCode.Decompiler/DecompilerSettings.cs +++ b/ICSharpCode.Decompiler/DecompilerSettings.cs @@ -686,6 +686,19 @@ namespace ICSharpCode.Decompiler } } + bool expandUsingDeclarations = false; + + [Browsable(false)] + public bool ExpandUsingDeclarations { + get { return expandUsingDeclarations; } + set { + if (expandUsingDeclarations != value) { + expandUsingDeclarations = value; + OnPropertyChanged(); + } + } + } + bool decompileMemberBodies = true; /// diff --git a/ICSharpCode.Decompiler/Output/TextTokenWriter.cs b/ICSharpCode.Decompiler/Output/TextTokenWriter.cs index 2f0a3d87b..ab5178bdf 100644 --- a/ICSharpCode.Decompiler/Output/TextTokenWriter.cs +++ b/ICSharpCode.Decompiler/Output/TextTokenWriter.cs @@ -23,9 +23,7 @@ using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.CSharp.OutputVisitor; using ICSharpCode.Decompiler.CSharp.Syntax; using ICSharpCode.Decompiler.IL; -using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; -using SRM = System.Reflection.Metadata; namespace ICSharpCode.Decompiler { @@ -40,9 +38,6 @@ namespace ICSharpCode.Decompiler bool firstUsingDeclaration; bool lastUsingDeclaration; - public bool FoldBraces = false; - public bool ExpandMemberDefinitions = false; - public TextTokenWriter(ITextOutput output, DecompilerSettings settings, IDecompilerTypeSystem typeSystem) { if (output == null) @@ -96,7 +91,7 @@ namespace ICSharpCode.Decompiler } if (firstUsingDeclaration) { - output.MarkFoldStart(defaultCollapsed: true); + output.MarkFoldStart(defaultCollapsed: !settings.ExpandUsingDeclarations); firstUsingDeclaration = false; } @@ -220,15 +215,15 @@ namespace ICSharpCode.Decompiler } if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration) braceLevelWithinType++; - if (nodeStack.OfType().Count() <= 1 || FoldBraces) { - output.MarkFoldStart(defaultCollapsed: !ExpandMemberDefinitions && braceLevelWithinType == 1); + if (nodeStack.OfType().Count() <= 1 || settings.FoldBraces) { + output.MarkFoldStart(defaultCollapsed: !settings.ExpandMemberDefinitions && braceLevelWithinType == 1); } output.Write("{"); break; case "}": output.Write('}'); if (role != Roles.RBrace) break; - if (nodeStack.OfType().Count() <= 1 || FoldBraces) + if (nodeStack.OfType().Count() <= 1 || settings.FoldBraces) output.MarkFoldEnd(); if (braceLevelWithinType >= 0) braceLevelWithinType--; diff --git a/ILSpy/DecompilationOptions.cs b/ILSpy/DecompilationOptions.cs index ebb97187a..229e876b0 100644 --- a/ILSpy/DecompilationOptions.cs +++ b/ILSpy/DecompilationOptions.cs @@ -83,6 +83,7 @@ namespace ICSharpCode.ILSpy var newSettings = this.DecompilerSettings = settings.Clone(); newSettings.SetLanguageVersion(languageVersion); newSettings.ExpandMemberDefinitions = displaySettings.ExpandMemberDefinitions; + newSettings.ExpandUsingDeclarations = displaySettings.ExpandUsingDeclarations; newSettings.FoldBraces = displaySettings.FoldBraces; newSettings.ShowDebugInfo = displaySettings.ShowDebugInfo; } diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index 88239f9d1..25b09f4f4 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -121,7 +121,7 @@ namespace ICSharpCode.ILSpy void WriteCode(ITextOutput output, DecompilerSettings settings, SyntaxTree syntaxTree, IDecompilerTypeSystem typeSystem) { syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); - TokenWriter tokenWriter = new TextTokenWriter(output, settings, typeSystem) { FoldBraces = settings.FoldBraces, ExpandMemberDefinitions = settings.ExpandMemberDefinitions }; + TokenWriter tokenWriter = new TextTokenWriter(output, settings, typeSystem); if (output is ISmartTextOutput highlightingOutput) { tokenWriter = new CSharpHighlightingTokenWriter(tokenWriter, highlightingOutput); } diff --git a/ILSpy/Options/DisplaySettings.cs b/ILSpy/Options/DisplaySettings.cs index caa02d470..e432c7238 100644 --- a/ILSpy/Options/DisplaySettings.cs +++ b/ILSpy/Options/DisplaySettings.cs @@ -155,6 +155,18 @@ namespace ICSharpCode.ILSpy.Options } } + bool expandUsingDeclarations = false; + + public bool ExpandUsingDeclarations { + get { return expandUsingDeclarations; } + set { + if (expandUsingDeclarations != value) { + expandUsingDeclarations = value; + OnPropertyChanged(); + } + } + } + bool showDebugInfo; public bool ShowDebugInfo { @@ -179,6 +191,7 @@ namespace ICSharpCode.ILSpy.Options this.SortResults = s.sortResults; this.FoldBraces = s.foldBraces; this.ExpandMemberDefinitions = s.expandMemberDefinitions; + this.ExpandUsingDeclarations = s.expandUsingDeclarations; } } } diff --git a/ILSpy/Options/DisplaySettingsPanel.xaml b/ILSpy/Options/DisplaySettingsPanel.xaml index 334d17aaf..49e54fb7e 100644 --- a/ILSpy/Options/DisplaySettingsPanel.xaml +++ b/ILSpy/Options/DisplaySettingsPanel.xaml @@ -67,6 +67,7 @@ Enable folding on all blocks in braces Sort results by fitness Expand member definitions after decompilation + Expand using declarations after decompilation diff --git a/ILSpy/Options/DisplaySettingsPanel.xaml.cs b/ILSpy/Options/DisplaySettingsPanel.xaml.cs index 4435287f6..07fa5bd78 100644 --- a/ILSpy/Options/DisplaySettingsPanel.xaml.cs +++ b/ILSpy/Options/DisplaySettingsPanel.xaml.cs @@ -107,6 +107,7 @@ namespace ICSharpCode.ILSpy.Options s.SortResults = (bool?)e.Attribute("SortResults") ?? true; s.FoldBraces = (bool?)e.Attribute("FoldBraces") ?? false; s.ExpandMemberDefinitions = (bool?)e.Attribute("ExpandMemberDefinitions") ?? false; + s.ExpandUsingDeclarations = (bool?)e.Attribute("ExpandUsingDeclarations") ?? false; return s; } @@ -126,6 +127,7 @@ namespace ICSharpCode.ILSpy.Options section.SetAttributeValue("SortResults", s.SortResults); section.SetAttributeValue("FoldBraces", s.FoldBraces); section.SetAttributeValue("ExpandMemberDefinitions", s.ExpandMemberDefinitions); + section.SetAttributeValue("ExpandUsingDeclarations", s.ExpandUsingDeclarations); XElement existingElement = root.Element("DisplaySettings"); if (existingElement != null)