From 6e5c7ad190a539903f068995bac117b15ca45cc3 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sat, 5 Apr 2025 11:19:01 +0800 Subject: [PATCH] Use ISavable interface instead of reflection --- Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs | 3 ++- Flow.Launcher.Infrastructure/Storage/JsonStorage.cs | 8 +++++--- Flow.Launcher/PublicAPIInstance.cs | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs b/Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs index 208e4bf11..f218c5d8d 100644 --- a/Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs +++ b/Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; +using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedCommands; using MemoryPack; @@ -16,7 +17,7 @@ namespace Flow.Launcher.Infrastructure.Storage /// /// It utilize MemoryPack, which means the object must be MemoryPackSerializable /// - public class BinaryStorage + public class BinaryStorage : ISavable { protected T? Data; diff --git a/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs b/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs index a3488124b..cdf3ae909 100644 --- a/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs +++ b/Flow.Launcher.Infrastructure/Storage/JsonStorage.cs @@ -1,18 +1,20 @@ -#nullable enable -using System; +using System; using System.Globalization; using System.IO; using System.Text.Json; using System.Threading.Tasks; using Flow.Launcher.Infrastructure.Logger; +using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedCommands; +#nullable enable + namespace Flow.Launcher.Infrastructure.Storage { /// /// Serialize object using json format. /// - public class JsonStorage where T : new() + public class JsonStorage : ISavable where T : new() { protected T? Data; diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 99d4cf233..50052f1c9 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -225,8 +225,8 @@ namespace Flow.Launcher { foreach (var value in _pluginJsonStorages.Values) { - var method = value.GetType().GetMethod("Save"); - method?.Invoke(value, null); + var savable = value as ISavable; + savable?.Save(); } } @@ -368,8 +368,8 @@ namespace Flow.Launcher { foreach (var value in _pluginBinaryStorages.Values) { - var method = value.GetType().GetMethod("Save"); - method?.Invoke(value, null); + var savable = value as ISavable; + savable?.Save(); } }