jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
11k stars 1.16k forks source link

Unit's IComparable.CompareTo should throw ArgumentException when obj is not of type Unit #875

Closed vjacquet closed 1 year ago

vjacquet commented 1 year ago

Hello,

As it is currently implemented, CompareTo always return 0, meaning equality, for objects of any type or even for null references. https://github.com/jbogard/MediatR/blob/a9e032dbf3d19aff0212fb12e4ba2c79450e61f4/src/MediatR.Contracts/Unit.cs#L47

This is inconsistent with Equals that correctly returns true only when the parameter is of the same type. https://github.com/jbogard/MediatR/blob/a9e032dbf3d19aff0212fb12e4ba2c79450e61f4/src/MediatR.Contracts/Unit.cs#L73

IComparable contract states that CompareTo throws ArgumentException when obj is not the same type as this instance.

A possible implementation could be

int IComparable.CompareTo(object? obj) => obj is Unit ? 0 : throw new ArgumentException();
jbogard commented 1 year ago

What issue is this causing for you?

vjacquet commented 1 year ago

None, but is it relevant? Well, I guess it is, because even though it is probably inconsequential, fixing it would be a breaking change.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 14 days with no activity.