Use ISavable interface instead of reflection

This commit is contained in:
Jack251970 2025-04-05 11:19:01 +08:00
parent e6d3d0fa9e
commit 6e5c7ad190
3 changed files with 11 additions and 8 deletions

View file

@ -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
/// <remarks>
/// It utilize MemoryPack, which means the object must be MemoryPackSerializable <see href="https://github.com/Cysharp/MemoryPack"/>
/// </remarks>
public class BinaryStorage<T>
public class BinaryStorage<T> : ISavable
{
protected T? Data;

View file

@ -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
{
/// <summary>
/// Serialize object using json format.
/// </summary>
public class JsonStorage<T> where T : new()
public class JsonStorage<T> : ISavable where T : new()
{
protected T? Data;

View file

@ -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();
}
}