Override all methods on value-types
Closed this issue · 0 comments
mgravell commented
First, try and write a test that uses reflection to discover all struct
(including non-public), and check whether all of Equals
, GetHashCode
and ToString
are overridden
Next: do that! Feel free to use:
public override string ToString() => nameof(ThisType);
public override bool Equals(object? obj) => ThrowHelper.ThrowNotSupportedException<bool>();
public override int GetHashCode() => ThrowHelper.ThrowNotSupportedException<int>();
if there is no sane comparison; if there is a sane comparison (for example, PooledValueTaskSource
could compare _source
and _token
), then it should also implement IEquatable<ThisType>
, with (typical)
public override Equals(object? obj) => obj is ThisType other && Equals(other);
public bool Equals(ThisType other) {...}