Skip to content

Commit 6e5c7ad

Browse files
committed
Use ISavable interface instead of reflection
1 parent e6d3d0f commit 6e5c7ad

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading.Tasks;
33
using Flow.Launcher.Infrastructure.Logger;
44
using Flow.Launcher.Infrastructure.UserSettings;
5+
using Flow.Launcher.Plugin;
56
using Flow.Launcher.Plugin.SharedCommands;
67
using MemoryPack;
78

@@ -16,7 +17,7 @@ namespace Flow.Launcher.Infrastructure.Storage
1617
/// <remarks>
1718
/// It utilize MemoryPack, which means the object must be MemoryPackSerializable <see href="https://github.com/Cysharp/MemoryPack"/>
1819
/// </remarks>
19-
public class BinaryStorage<T>
20+
public class BinaryStorage<T> : ISavable
2021
{
2122
protected T? Data;
2223

Flow.Launcher.Infrastructure/Storage/JsonStorage.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
#nullable enable
2-
using System;
1+
using System;
32
using System.Globalization;
43
using System.IO;
54
using System.Text.Json;
65
using System.Threading.Tasks;
76
using Flow.Launcher.Infrastructure.Logger;
7+
using Flow.Launcher.Plugin;
88
using Flow.Launcher.Plugin.SharedCommands;
99

10+
#nullable enable
11+
1012
namespace Flow.Launcher.Infrastructure.Storage
1113
{
1214
/// <summary>
1315
/// Serialize object using json format.
1416
/// </summary>
15-
public class JsonStorage<T> where T : new()
17+
public class JsonStorage<T> : ISavable where T : new()
1618
{
1719
protected T? Data;
1820

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ public void SavePluginSettings()
225225
{
226226
foreach (var value in _pluginJsonStorages.Values)
227227
{
228-
var method = value.GetType().GetMethod("Save");
229-
method?.Invoke(value, null);
228+
var savable = value as ISavable;
229+
savable?.Save();
230230
}
231231
}
232232

@@ -368,8 +368,8 @@ public void SavePluginCaches()
368368
{
369369
foreach (var value in _pluginBinaryStorages.Values)
370370
{
371-
var method = value.GetType().GetMethod("Save");
372-
method?.Invoke(value, null);
371+
var savable = value as ISavable;
372+
savable?.Save();
373373
}
374374
}
375375

0 commit comments

Comments
 (0)