From 23c595f675e7ae90c070b9301881d0cd95f264ce Mon Sep 17 00:00:00 2001 From: Ske Date: Sat, 13 Jun 2020 13:18:21 +0200 Subject: [PATCH] Extract ProxyTag to separate file --- PluralKit.Core/Models/PKMember.cs | 30 --------------------------- PluralKit.Core/Models/ProxyTag.cs | 34 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 PluralKit.Core/Models/ProxyTag.cs diff --git a/PluralKit.Core/Models/PKMember.cs b/PluralKit.Core/Models/PKMember.cs index 656fcaee..969b48b0 100644 --- a/PluralKit.Core/Models/PKMember.cs +++ b/PluralKit.Core/Models/PKMember.cs @@ -46,34 +46,4 @@ namespace PluralKit.Core { return $"{guildDisplayName ?? DisplayName ?? Name} {systemTag}"; } } - - public struct ProxyTag - { - public ProxyTag(string prefix, string suffix) - { - // Normalize empty strings to null for DB - Prefix = prefix?.Length == 0 ? null : prefix; - Suffix = suffix?.Length == 0 ? null : suffix; - } - - [JsonProperty("prefix")] public string Prefix { get; set; } - [JsonProperty("suffix")] public string Suffix { get; set; } - - [JsonIgnore] public string ProxyString => $"{Prefix ?? ""}text{Suffix ?? ""}"; - - public bool IsEmpty => Prefix == null && Suffix == null; - - public bool Equals(ProxyTag other) => Prefix == other.Prefix && Suffix == other.Suffix; - - public override bool Equals(object obj) => obj is ProxyTag other && Equals(other); - - public override int GetHashCode() - { - unchecked - { - return ((Prefix != null ? Prefix.GetHashCode() : 0) * 397) ^ - (Suffix != null ? Suffix.GetHashCode() : 0); - } - } - } } \ No newline at end of file diff --git a/PluralKit.Core/Models/ProxyTag.cs b/PluralKit.Core/Models/ProxyTag.cs new file mode 100644 index 00000000..c00a5e50 --- /dev/null +++ b/PluralKit.Core/Models/ProxyTag.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; + +namespace PluralKit.Core +{ + public struct ProxyTag + { + public ProxyTag(string prefix, string suffix) + { + // Normalize empty strings to null for DB + Prefix = prefix?.Length == 0 ? null : prefix; + Suffix = suffix?.Length == 0 ? null : suffix; + } + + [JsonProperty("prefix")] public string Prefix { get; set; } + [JsonProperty("suffix")] public string Suffix { get; set; } + + [JsonIgnore] public string ProxyString => $"{Prefix ?? ""}text{Suffix ?? ""}"; + + public bool IsEmpty => Prefix == null && Suffix == null; + + public bool Equals(ProxyTag other) => Prefix == other.Prefix && Suffix == other.Suffix; + + public override bool Equals(object obj) => obj is ProxyTag other && Equals(other); + + public override int GetHashCode() + { + unchecked + { + return ((Prefix != null ? Prefix.GetHashCode() : 0) * 397) ^ + (Suffix != null ? Suffix.GetHashCode() : 0); + } + } + } +} \ No newline at end of file