Closed djcarter85 closed 6 years ago
Yes!
You cannot use the ComparableBase<T>
or ComparableBaseWithOperators<T>
with structs, since they cannot have base classes. However, you can use ComparableImplementations
, as documented here.
I just checked in some unit tests to show how this is done. This example has a struct that implements IComparable<T>
/ IEquatable<T>
/ IComparable
(and overrides Equals
and GetHashCode
). If you want to go a step further and support operators, you can also write those operators out and forward them to ComparableImplementations
following that same pattern.
Is there a way of automatically implementing the required comparison and equality operators for structs?