louthy / language-ext

C# functional language extensions - a base class library for functional programming
MIT License
6.39k stars 414 forks source link

Add System.IComparable to NewType #804

Closed Bert-Proesmans closed 4 years ago

Bert-Proesmans commented 4 years ago

Hi, I'm using a custom NewType within a viewmodel proxy. Since it's intended to be read-only I leak the newtype type to the view as a property. The proxy type is bound to a DataGrid, but the column of my newtype isn't sortable. I found out that it does work by implementing System.IComparable (note the lack of type parameter!) manually on my newtype. The alternative would be to hook on the sorting event, construct an expression based comparer and use that one for the actual sorting.

I propose to add the non generic interface to the NewType base class, unless there is a special reason not to ofcourse. This is not anything of high priority, for now i just have to remember to manually implement the required interface.

Thanks.

EDIT; I'm willing to contribute this change to the repository, of course. So far i'm just curious if there was any special reason not to implement the non-generic variant.

louthy commented 4 years ago

@Bert-Proesmans IComparable has now been implemented for all types that implement IComparable<...>.

Released to nu-get in v3.5.13

The only reason, I didn't add it, is because I thought the non-generic IComparable was just an artefact from the past, and not really used any more ;-)

Bert-Proesmans commented 4 years ago

Thank you for the addition! 👍