#region Header // _,-'/-'/ // . __,-; ,'( '/ // \. `-.__`-._`:_,-._ _ , . `` // `:-._,------' ` _,`--` -: `_ , ` ,' : // `---..__,,--' (C) 2023 ` -'. -' // # Vita-Nex [http://core.vita-nex.com] # // {o)xxx|===============- # -===============|xxx(o} // # # #endregion #region References using System; using System.Collections.Generic; using Server; #endregion namespace VitaNex { public static class Pair { public static Pair Create(T1 left, T2 right) { return Pair.Create(left, right); } } /// /// It's kinda like a Tuple, but it's a Pair. /// [PropertyObject] public struct Pair : IEquatable>, IEquatable> { public static Pair Create(TLeft left, TRight right) { return new Pair(left, right); } [CommandProperty(AccessLevel.Counselor, true)] public TLeft Left { get; private set; } [CommandProperty(AccessLevel.Counselor, true)] public TRight Right { get; private set; } public Pair(Pair p) : this(p.Left, p.Right) { } public Pair(KeyValuePair kvp) : this(kvp.Key, kvp.Value) { } public Pair(TLeft left, TRight right) : this() { Left = left; Right = right; } public override int GetHashCode() { unchecked { int l = Left != null ? Left.GetHashCode() : 0, r = Right != null ? Right.GetHashCode() : 0; return (l * 397) ^ r; } } public override bool Equals(object obj) { return (obj is KeyValuePair && Equals((KeyValuePair)obj)) || (obj is Pair && Equals((Pair)obj)); } public bool Equals(KeyValuePair other) { return Equals(Left, other.Key) && Equals(Right, other.Value); } public bool Equals(Pair other) { return Equals(Left, other.Left) && Equals(Right, other.Right); } public static bool operator ==(Pair l, Pair r) { return Equals(l, r); } public static bool operator !=(Pair l, Pair r) { return !Equals(l, r); } public static implicit operator KeyValuePair(Pair p) { return new KeyValuePair(p.Left, p.Right); } public static implicit operator Pair(KeyValuePair p) { return new Pair(p.Key, p.Value); } } }