From bf76abf93fd6fe3e577b98afa09437d9a79abe33 Mon Sep 17 00:00:00 2001 From: miloush Date: Tue, 12 Sep 2023 12:15:55 +0100 Subject: [PATCH] Include inherited constructors and nested types --- ILSpy/TreeNodes/TypeTreeNode.cs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/ILSpy/TreeNodes/TypeTreeNode.cs b/ILSpy/TreeNodes/TypeTreeNode.cs index 9623d9bc74..b10ff32e7d 100644 --- a/ILSpy/TreeNodes/TypeTreeNode.cs +++ b/ILSpy/TreeNodes/TypeTreeNode.cs @@ -17,6 +17,7 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Collections.Generic; using System.Linq; using System.Windows.Media; @@ -101,13 +102,17 @@ protected override void OnFilterSettingsChanged() protected override void LoadChildren() { - loadedInheritedMembers = FilterSettings.ShowApiInherited; - GetMemberOptions inheritanceOptions = FilterSettings.ShowApiInherited ? GetMemberOptions.None : GetMemberOptions.IgnoreInheritedMembers; if (TypeDefinition.DirectBaseTypes.Any()) this.Children.Add(new BaseTypesTreeNode(ParentAssemblyNode.LoadedAssembly.GetPEFileOrNull(), TypeDefinition)); if (!TypeDefinition.IsSealed) this.Children.Add(new DerivedTypesTreeNode(ParentAssemblyNode.AssemblyList, TypeDefinition)); - foreach (var nestedType in TypeDefinition.NestedTypes.OrderBy(t => t.Name, NaturalStringComparer.Instance)) + loadedInheritedMembers = FilterSettings.ShowApiInherited; + IEnumerable nestedTypes = GetMembers(TypeDefinition, t => t.NestedTypes, FilterSettings.ShowApiInherited); + IEnumerable fields = GetMembers(TypeDefinition, t => t.Fields, FilterSettings.ShowApiInherited); + IEnumerable properties = GetMembers(TypeDefinition, t => t.Properties, FilterSettings.ShowApiInherited); + IEnumerable events = GetMembers(TypeDefinition, t => t.Events, FilterSettings.ShowApiInherited); + IEnumerable methods = GetMembers(TypeDefinition, t => t.Methods, FilterSettings.ShowApiInherited); + foreach (var nestedType in nestedTypes.OrderBy(t => t.Name, NaturalStringComparer.Instance)) { this.Children.Add(new TypeTreeNode(nestedType, ParentAssemblyNode)); } @@ -121,20 +126,20 @@ protected override void LoadChildren() } else { - foreach (var field in TypeDefinition.GetFields(null, inheritanceOptions).OrderBy(f => f.Name, NaturalStringComparer.Instance)) + foreach (var field in fields.OrderBy(f => f.Name, NaturalStringComparer.Instance)) { this.Children.Add(new FieldTreeNode(field)); } } - foreach (var property in TypeDefinition.GetProperties(null, inheritanceOptions).OrderBy(p => p.Name, NaturalStringComparer.Instance)) + foreach (var property in properties.OrderBy(p => p.Name, NaturalStringComparer.Instance)) { this.Children.Add(new PropertyTreeNode(property)); } - foreach (var ev in TypeDefinition.GetEvents(null, inheritanceOptions).OrderBy(e => e.Name, NaturalStringComparer.Instance)) + foreach (var ev in events.OrderBy(e => e.Name, NaturalStringComparer.Instance)) { this.Children.Add(new EventTreeNode(ev)); } - foreach (var method in TypeDefinition.GetMethods(null, inheritanceOptions).OrderBy(m => m.Name, NaturalStringComparer.Instance)) + foreach (var method in methods.OrderBy(m => m.Name, NaturalStringComparer.Instance)) { if (method.MetadataToken.IsNil) continue; @@ -142,6 +147,16 @@ protected override void LoadChildren() } } + private IEnumerable GetMembers(ITypeDefinition type, Func> selector, bool includeInherited) + { + IEnumerable allMembers = selector(type); + if (includeInherited) + foreach (var baseType in type.GetNonInterfaceBaseTypes().Reverse().Select(t => t.GetDefinition())) + if (baseType != null && baseType != type) + allMembers = allMembers.Concat(selector(baseType)); + return allMembers; + } + public override bool CanExpandRecursively => true; public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)