using System; using System.Collections.Generic; namespace KamiLib.Configuration; public sealed record Setting(T Value) : IEquatable where T : notnull { public T Value = Value; public override string ToString() => Value.ToString() ?? "Null"; public bool Equals(T? other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return EqualityComparer.Default.Equals(Value, other); } public static bool operator ==(Setting leftSide, T rightSide) { return leftSide.Equals(rightSide); } public static bool operator !=(Setting leftSide, T rightSide) { return !leftSide.Equals(rightSide); } public static implicit operator bool(Setting obj) { if (obj.Value is bool value) { return value; } throw new Exception("Invalid implicit conversion to bool"); } public override int GetHashCode() { // ReSharper disable once NonReadonlyMemberInGetHashCode return EqualityComparer.Default.GetHashCode(Value); } }