From a0c70a34324897b3d7803e621bbf1b9b278e339e Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sat, 8 Oct 2022 16:33:39 +0800 Subject: [PATCH] Inherit --- .../UserSettings/CustomShortcutModel.cs | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/CustomShortcutModel.cs b/Flow.Launcher.Infrastructure/UserSettings/CustomShortcutModel.cs index 750adf9ee..9df2633bc 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/CustomShortcutModel.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/CustomShortcutModel.cs @@ -1,15 +1,34 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Text.Json.Serialization; namespace Flow.Launcher.Infrastructure.UserSettings { - public class CustomShortcutModel + public class CustomShortcutBaseModel { public string Key { get; set; } - public string Value { get; set; } + + [JsonIgnore] + public Func Expand { get; set; } = () => { return ""; }; + + public override bool Equals(object obj) + { + return obj is CustomShortcutBaseModel other && + Key == other.Key; + } + + public override int GetHashCode() + { + return HashCode.Combine(Key); + } + }; + + public class CustomShortcutModel : CustomShortcutBaseModel + { + public string Value + { + get { return Expand(); } + set { Expand = () => { return value; }; } + } public CustomShortcutModel(string key, string value) { @@ -17,22 +36,10 @@ namespace Flow.Launcher.Infrastructure.UserSettings Value = value; } - public override bool Equals(object obj) - { - return obj is CustomShortcutModel other && - Key == other.Key && - Value == other.Value; - } - - public override int GetHashCode() - { - return HashCode.Combine(Key, Value); - } - public void Deconstruct(out string key, out string value) { key = Key; - value = Value; + value = Expand(); } public static implicit operator (string Key, string Value)(CustomShortcutModel shortcut)