Comparable WalletId

This commit is contained in:
nicolas.dorier 2018-10-09 23:44:32 +09:00
parent a28814bc0e
commit 3c58bff803

View file

@ -11,6 +11,8 @@ namespace BTCPayServer
static readonly Regex _WalletStoreRegex = new Regex("^S-([a-zA-Z0-9]{30,60})-([a-zA-Z]{2,5})$");
public static bool TryParse(string str, out WalletId walletId)
{
if (str == null)
throw new ArgumentNullException(nameof(str));
walletId = null;
WalletId w = new WalletId();
var match = _WalletStoreRegex.Match(str);
@ -32,8 +34,37 @@ namespace BTCPayServer
}
public string StoreId { get; set; }
public string CryptoCode { get; set; }
public override bool Equals(object obj)
{
WalletId item = obj as WalletId;
if (item == null)
return false;
return ToString().Equals(item.ToString(), StringComparison.InvariantCulture);
}
public static bool operator ==(WalletId a, WalletId b)
{
if (System.Object.ReferenceEquals(a, b))
return true;
if (((object)a == null) || ((object)b == null))
return false;
return a.ToString() == b.ToString();
}
public static bool operator !=(WalletId a, WalletId b)
{
return !(a == b);
}
public override int GetHashCode()
{
return ToString().GetHashCode(StringComparison.Ordinal);
}
public override string ToString()
{
if (StoreId == null || CryptoCode == null)
return "";
return $"S-{StoreId}-{CryptoCode.ToUpperInvariant()}";
}
}