// // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published // by the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see https://www.gnu.org/licenses/. // namespace slskd { using System; /// /// Uniquely identifies a Wait. /// public sealed class WaitKey : IEquatable { /// /// Initializes a new instance of the class. /// /// The parts which make up the key. public WaitKey(params object[] tokenParts) { TokenParts = tokenParts; Token = string.Join(":", TokenParts); } /// /// Gets the wait token. /// public string Token { get; } /// /// Gets the parts which make up the key. /// public object[] TokenParts { get; } public static bool operator !=(WaitKey lhs, WaitKey rhs) { return !lhs.Equals(rhs); } public static bool operator ==(WaitKey lhs, WaitKey rhs) { return lhs.Equals(rhs); } /// /// Compares the specified to this instance. /// /// The object to which to compare. /// A value indicating whether the specified object is equal to this instance. public override bool Equals(object obj) { try { return Equals((WaitKey)obj); } catch (InvalidCastException) { return false; } } /// /// Compares the specified WaitKey to this instance. /// /// The WaitKey to which to compare. /// A value indicating whether the specified WaitKey is equal to this instance. public bool Equals(WaitKey other) { return Token == other.Token; } /// /// Returns the hash code of this instance. /// /// The hash code of this instance. public override int GetHashCode() { #if NETSTANDARD2_0 return string.IsNullOrEmpty(Token) ? 0 : Token.GetHashCode(); #else return string.IsNullOrEmpty(Token) ? 0 : Token.GetHashCode(StringComparison.InvariantCulture); #endif } /// /// Returns the string representation of the key. /// /// The string representation of the key. public override string ToString() { return Token; } } }