Migrate to type-safe model ID structs
This commit is contained in:
24
PluralKit.Core/Models/SwitchId.cs
Normal file
24
PluralKit.Core/Models/SwitchId.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public readonly struct SwitchId: INumericId<SwitchId, int>
|
||||
{
|
||||
public int Value { get; }
|
||||
|
||||
public SwitchId(int value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public bool Equals(SwitchId other) => Value == other.Value;
|
||||
|
||||
public override bool Equals(object obj) => obj is SwitchId other && Equals(other);
|
||||
|
||||
public override int GetHashCode() => Value;
|
||||
|
||||
public static bool operator ==(SwitchId left, SwitchId right) => left.Equals(right);
|
||||
|
||||
public static bool operator !=(SwitchId left, SwitchId right) => !left.Equals(right);
|
||||
|
||||
public int CompareTo(SwitchId other) => Value.CompareTo(other.Value);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user