From f9048cd3690c152a70d8a98fa81809d7b6c5355f Mon Sep 17 00:00:00 2001 From: tom-englert Date: Wed, 24 Dec 2025 10:55:15 +0100 Subject: [PATCH] Do not use ObservableObject when ObservableObjectBase is sufficient. --- ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs | 2 +- ILSpy.ReadyToRun/ReadyToRunOptions.cs | 2 +- ILSpy/AssemblyTree/AssemblyTreeModel.cs | 14 ++++++++------ ILSpy/Docking/DockWorkspace.cs | 2 +- ILSpy/LanguageSettings.cs | 2 +- ILSpy/MainWindowViewModel.cs | 2 +- ILSpy/Options/DisplaySettings.cs | 2 +- ILSpy/Options/DisplaySettingsViewModel.cs | 2 +- ILSpy/Options/MiscSettings.cs | 2 +- ILSpy/Options/MiscSettingsViewModel.cs | 2 +- ILSpy/Options/OptionsDialogViewModel.cs | 4 ++-- ILSpy/ViewModels/CompareViewModel.cs | 2 +- ILSpy/ViewModels/ManageAssemblyListsViewModel.cs | 2 +- ILSpy/ViewModels/PaneModel.cs | 2 +- ILSpy/ViewModels/UpdatePanelViewModel.cs | 2 +- TestPlugin/CustomOptionPage.xaml.cs | 4 ++-- 16 files changed, 25 insertions(+), 23 deletions(-) diff --git a/ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs b/ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs index 5eb6ae812..bb4c6d440 100644 --- a/ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs +++ b/ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs @@ -38,7 +38,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun [ExportOptionPage(Order = 40)] [NonShared] - class ReadyToRunOptionsViewModel : ObservableObject, IOptionPage + class ReadyToRunOptionsViewModel : ObservableObjectBase, IOptionPage { private ReadyToRunOptions options; diff --git a/ILSpy.ReadyToRun/ReadyToRunOptions.cs b/ILSpy.ReadyToRun/ReadyToRunOptions.cs index d2bb11215..c2b94929c 100644 --- a/ILSpy.ReadyToRun/ReadyToRunOptions.cs +++ b/ILSpy.ReadyToRun/ReadyToRunOptions.cs @@ -24,7 +24,7 @@ using TomsToolbox.Wpf; namespace ICSharpCode.ILSpy.ReadyToRun { - internal partial class ReadyToRunOptions : ObservableObject, ISettingsSection + internal partial class ReadyToRunOptions : ObservableObjectBase, ISettingsSection { private static readonly XNamespace ns = "http://www.ilspy.net/ready-to-run"; diff --git a/ILSpy/AssemblyTree/AssemblyTreeModel.cs b/ILSpy/AssemblyTree/AssemblyTreeModel.cs index 675eeda4d..a7b8f2752 100644 --- a/ILSpy/AssemblyTree/AssemblyTreeModel.cs +++ b/ILSpy/AssemblyTree/AssemblyTreeModel.cs @@ -72,6 +72,8 @@ namespace ICSharpCode.ILSpy.AssemblyTree private readonly LanguageService languageService; private readonly IExportProvider exportProvider; + private static Dispatcher UIThread => Application.Current.Dispatcher; + public AssemblyTreeModel(SettingsService settingsService, LanguageService languageService, IExportProvider exportProvider) { this.settingsService = settingsService; @@ -198,7 +200,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree { var cmdArgs = CommandLineArguments.Create(args); - await Dispatcher.InvokeAsync(async () => { + await UIThread.InvokeAsync(async () => { if (!HandleCommandLineArguments(cmdArgs)) return; @@ -256,7 +258,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree // Make sure we wait for assemblies being loaded... // BeginInvoke in LoadedAssembly.LookupReferencedAssemblyInternal - await Dispatcher.InvokeAsync(delegate { }, DispatcherPriority.Normal); + await UIThread.InvokeAsync(delegate { }, DispatcherPriority.Normal); if (mr is { ParentModule.MetadataFile: not null }) { @@ -401,7 +403,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree AssemblyList.Open(sessionSettings.ActiveAutoLoadedAssembly, true); } - Dispatcher.BeginInvoke(DispatcherPriority.Loaded, OpenAssemblies); + UIThread.BeginInvoke(DispatcherPriority.Loaded, OpenAssemblies); } private async Task OpenAssemblies() @@ -536,14 +538,14 @@ namespace ICSharpCode.ILSpy.AssemblyTree if (SelectedItem == node) { - Dispatcher.BeginInvoke(RefreshDecompiledView); + UIThread.BeginInvoke(RefreshDecompiledView); } else { activeView?.ScrollIntoView(node); SelectedItem = node; - Dispatcher.BeginInvoke(DispatcherPriority.Background, () => { + UIThread.BeginInvoke(DispatcherPriority.Background, () => { activeView?.ScrollIntoView(node); }); } @@ -795,7 +797,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree { ContextMenuProvider.ContextMenuClosed -= ContextMenuClosed; - Dispatcher.BeginInvoke(DispatcherPriority.Background, () => { + UIThread.BeginInvoke(DispatcherPriority.Background, () => { if (Mouse.RightButton != MouseButtonState.Pressed) { RefreshDecompiledView(); diff --git a/ILSpy/Docking/DockWorkspace.cs b/ILSpy/Docking/DockWorkspace.cs index 3b33fd687..07de6b3e1 100644 --- a/ILSpy/Docking/DockWorkspace.cs +++ b/ILSpy/Docking/DockWorkspace.cs @@ -46,7 +46,7 @@ namespace ICSharpCode.ILSpy.Docking { [Export] [Shared] - public class DockWorkspace : ObservableObject, ILayoutUpdateStrategy + public class DockWorkspace : ObservableObjectBase, ILayoutUpdateStrategy { private readonly IExportProvider exportProvider; diff --git a/ILSpy/LanguageSettings.cs b/ILSpy/LanguageSettings.cs index 4b6b78e07..96dfd1f77 100644 --- a/ILSpy/LanguageSettings.cs +++ b/ILSpy/LanguageSettings.cs @@ -31,7 +31,7 @@ namespace ICSharpCode.ILSpy /// /// Represents the filters applied to the tree view. /// - public class LanguageSettings : ObservableObject, IChildSettings + public class LanguageSettings : ObservableObjectBase, IChildSettings { /// /// This dictionary is necessary to remember language versions across language changes. For example, diff --git a/ILSpy/MainWindowViewModel.cs b/ILSpy/MainWindowViewModel.cs index 009cc1d09..ffc83cc7e 100644 --- a/ILSpy/MainWindowViewModel.cs +++ b/ILSpy/MainWindowViewModel.cs @@ -27,7 +27,7 @@ namespace ICSharpCode.ILSpy { [Export] [Shared] - public class MainWindowViewModel(SettingsService settingsService, LanguageService languageService, DockWorkspace dockWorkspace) : ObservableObject + public class MainWindowViewModel(SettingsService settingsService, LanguageService languageService, DockWorkspace dockWorkspace) : ObservableObjectBase { public DockWorkspace Workspace { get; } = dockWorkspace; diff --git a/ILSpy/Options/DisplaySettings.cs b/ILSpy/Options/DisplaySettings.cs index 95c9d02d1..a65748446 100644 --- a/ILSpy/Options/DisplaySettings.cs +++ b/ILSpy/Options/DisplaySettings.cs @@ -28,7 +28,7 @@ namespace ICSharpCode.ILSpy.Options /// /// Description of DisplaySettings. /// - public class DisplaySettings : ObservableObject, ISettingsSection + public class DisplaySettings : ObservableObjectBase, ISettingsSection { FontFamily selectedFont; public FontFamily SelectedFont { diff --git a/ILSpy/Options/DisplaySettingsViewModel.cs b/ILSpy/Options/DisplaySettingsViewModel.cs index 580e665c9..ec581b18d 100644 --- a/ILSpy/Options/DisplaySettingsViewModel.cs +++ b/ILSpy/Options/DisplaySettingsViewModel.cs @@ -14,7 +14,7 @@ namespace ICSharpCode.ILSpy.Options { [ExportOptionPage(Order = 20)] [NonShared] - public class DisplaySettingsViewModel : ObservableObject, IOptionPage + public class DisplaySettingsViewModel : ObservableObjectBase, IOptionPage { private DisplaySettings settings = new(); private FontFamily[] fontFamilies; diff --git a/ILSpy/Options/MiscSettings.cs b/ILSpy/Options/MiscSettings.cs index 43f12ad79..32a1597c3 100644 --- a/ILSpy/Options/MiscSettings.cs +++ b/ILSpy/Options/MiscSettings.cs @@ -23,7 +23,7 @@ using TomsToolbox.Wpf; namespace ICSharpCode.ILSpyX.Settings { - public class MiscSettings : ObservableObject, ISettingsSection + public class MiscSettings : ObservableObjectBase, ISettingsSection { private bool allowMultipleInstances; private bool loadPreviousAssemblies = true; diff --git a/ILSpy/Options/MiscSettingsViewModel.cs b/ILSpy/Options/MiscSettingsViewModel.cs index 14b0f3123..49c598395 100644 --- a/ILSpy/Options/MiscSettingsViewModel.cs +++ b/ILSpy/Options/MiscSettingsViewModel.cs @@ -34,7 +34,7 @@ namespace ICSharpCode.ILSpy.Options { [ExportOptionPage(Order = 30)] [NonShared] - public class MiscSettingsViewModel : ObservableObject, IOptionPage + public class MiscSettingsViewModel : ObservableObjectBase, IOptionPage { private MiscSettings settings; public MiscSettings Settings { diff --git a/ILSpy/Options/OptionsDialogViewModel.cs b/ILSpy/Options/OptionsDialogViewModel.cs index dce364c8e..eb8a7cd94 100644 --- a/ILSpy/Options/OptionsDialogViewModel.cs +++ b/ILSpy/Options/OptionsDialogViewModel.cs @@ -27,14 +27,14 @@ using TomsToolbox.Wpf; namespace ICSharpCode.ILSpy.Options { - public class OptionsItemViewModel(IOptionPage content) : ObservableObject + public class OptionsItemViewModel(IOptionPage content) : ObservableObjectBase { public string Title { get; } = content.Title; public IOptionPage Content { get; } = content; } - public class OptionsDialogViewModel : ObservableObject + public class OptionsDialogViewModel : ObservableObjectBase { private IOptionPage? selectedPage; diff --git a/ILSpy/ViewModels/CompareViewModel.cs b/ILSpy/ViewModels/CompareViewModel.cs index 9a038ba66..bc71ff01b 100644 --- a/ILSpy/ViewModels/CompareViewModel.cs +++ b/ILSpy/ViewModels/CompareViewModel.cs @@ -46,7 +46,7 @@ namespace ICSharpCode.ILSpy.ViewModels using TomsToolbox.Wpf; - class CompareViewModel : ObservableObject + class CompareViewModel : ObservableObjectBase { private readonly TabPageModel tabPage; private readonly AssemblyTreeModel assemblyTreeModel; diff --git a/ILSpy/ViewModels/ManageAssemblyListsViewModel.cs b/ILSpy/ViewModels/ManageAssemblyListsViewModel.cs index 9d637b24e..edda002fc 100644 --- a/ILSpy/ViewModels/ManageAssemblyListsViewModel.cs +++ b/ILSpy/ViewModels/ManageAssemblyListsViewModel.cs @@ -34,7 +34,7 @@ using DelegateCommand = ICSharpCode.ILSpy.Commands.DelegateCommand; namespace ICSharpCode.ILSpy.ViewModels { - public class ManageAssemblyListsViewModel : ObservableObject + public class ManageAssemblyListsViewModel : ObservableObjectBase { private readonly AssemblyListManager manager; private readonly Window parent; diff --git a/ILSpy/ViewModels/PaneModel.cs b/ILSpy/ViewModels/PaneModel.cs index aeea0cd5a..7c2633e7d 100644 --- a/ILSpy/ViewModels/PaneModel.cs +++ b/ILSpy/ViewModels/PaneModel.cs @@ -27,7 +27,7 @@ using TomsToolbox.Wpf; namespace ICSharpCode.ILSpy.ViewModels { - public abstract class PaneModel : ObservableObject + public abstract class PaneModel : ObservableObjectBase { private readonly Throttle titleChangeThrottle; diff --git a/ILSpy/ViewModels/UpdatePanelViewModel.cs b/ILSpy/ViewModels/UpdatePanelViewModel.cs index 48ae5f3e7..a20ad8192 100644 --- a/ILSpy/ViewModels/UpdatePanelViewModel.cs +++ b/ILSpy/ViewModels/UpdatePanelViewModel.cs @@ -28,7 +28,7 @@ namespace ICSharpCode.ILSpy.ViewModels; [Export] [NonShared] -public class UpdatePanelViewModel : ObservableObject +public class UpdatePanelViewModel : ObservableObjectBase { bool isPanelVisible; string updateAvailableDownloadUrl; diff --git a/TestPlugin/CustomOptionPage.xaml.cs b/TestPlugin/CustomOptionPage.xaml.cs index b54cfba34..d423a5c32 100644 --- a/TestPlugin/CustomOptionPage.xaml.cs +++ b/TestPlugin/CustomOptionPage.xaml.cs @@ -25,7 +25,7 @@ namespace TestPlugin [ExportOptionPage(Order = 0)] [NonShared] - class CustomOptionsViewModel : ObservableObject, IOptionPage + class CustomOptionsViewModel : ObservableObjectBase, IOptionPage { private Options options; @@ -47,7 +47,7 @@ namespace TestPlugin } } - class Options : ObservableObject, ISettingsSection + class Options : ObservableObjectBase, ISettingsSection { static readonly XNamespace ns = "http://www.ilspy.net/testplugin";