From 723b4b183e5625853a6cb4aa91426403bb75c110 Mon Sep 17 00:00:00 2001 From: tom-englert Date: Sun, 18 Aug 2024 15:03:08 +0200 Subject: [PATCH] Avoid round-trip from view into model --- ILSpy/Analyzers/AnalyzerTreeView.cs | 40 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/ILSpy/Analyzers/AnalyzerTreeView.cs b/ILSpy/Analyzers/AnalyzerTreeView.cs index 5f53e99064..97b65b6f34 100644 --- a/ILSpy/Analyzers/AnalyzerTreeView.cs +++ b/ILSpy/Analyzers/AnalyzerTreeView.cs @@ -50,26 +50,6 @@ public AnalyzerTreeView() this.BorderThickness = new(); this.Root = new AnalyzerRootNode(); ContextMenuProvider.Add(this); - MessageBus.Subscribers += (sender, e) => CurrentAssemblyList_Changed(sender, e); - } - - - void CurrentAssemblyList_Changed(object sender, NotifyCollectionChangedEventArgs e) - { - if (e.Action == NotifyCollectionChangedAction.Reset) - { - this.Root.Children.Clear(); - } - else - { - List removedAssemblies = new List(); - if (e.OldItems != null) - removedAssemblies.AddRange(e.OldItems.Cast()); - List addedAssemblies = new List(); - if (e.NewItems != null) - addedAssemblies.AddRange(e.NewItems.Cast()); - ((AnalyzerRootNode)this.Root).HandleAssemblyListChanged(removedAssemblies, addedAssemblies); - } } public void Show() @@ -144,6 +124,26 @@ public void Analyze(IEntity entity) sealed class AnalyzerRootNode : AnalyzerTreeNode { + public AnalyzerRootNode() + { + MessageBus.Subscribers += (sender, e) => CurrentAssemblyList_Changed(sender, e); + } + + void CurrentAssemblyList_Changed(object sender, NotifyCollectionChangedEventArgs e) + { + if (e.Action == NotifyCollectionChangedAction.Reset) + { + this.Children.Clear(); + } + else + { + var removedAssemblies = e.OldItems?.Cast().ToArray() ?? []; + var addedAssemblies = e.NewItems?.Cast().ToArray() ?? []; + + HandleAssemblyListChanged(removedAssemblies, addedAssemblies); + } + } + public override bool HandleAssemblyListChanged(ICollection removedAssemblies, ICollection addedAssemblies) { this.Children.RemoveAll(