← Back to team overview

nunit-dev team mailing list archive

Re: Feature 676560 - IEquatable

 

On Sat, Oct 22, 2011 at 02:11, Charlie Poole <charlie@xxxxxxxxx> wrote:

> Hi Simone,
>
> I figured I could wait a few hours before writing you again, because
> of your time zone. I
> guess you're a night owl!
>

Well on friday night unless I'm out I can stay awake until 1 AM usually ;)


>
> On Fri, Oct 21, 2011 at 2:53 PM, Simone Busoli <simone.busoli@xxxxxxxxx>
> wrote:
> > Hi, unless I'm missing something - Charlie said on the "bug" page that
> it's
> > not trivial - all I would do is insert an additional routine call before
> the
> > default fallback to x.Equals(y) in NUnitEqualityComparer which would:
>
> Two issues about this:
>
> 1. Inserting the change right before the fallback x.Equals(y) sounds
> good to me at least
> for now. It will mess up folks with a class that implements
> ICollection, but I think we
> can live with that.
>

Yes, I thought about it, I think there's no perfect solution here. Putting
the new code before the object.Equals fallback we choose to give precedence
to the implementation of IEnumerable, ICollection, .. over IEquatable. That
said, I think it's unusual to implement both IEnumerable and IEquatable.


>
> 2. The code itself is going to be reflection-based and reflection on
> generic types is
> a bit hairy, but I think it's doable.
>
> > check if both x and y implement IEquatable<>
> > check that they both implement IEquatable of the same T
> > if the two above apply, call the IEquatable<T>.Equals method somehow,
> using
> > reflection perhaps
>
> I think you can check the types first and ensure that they are the
> same type. I'm
> not sure there's a case for a type T1 that implements IEquatable<T2>, but I
> could be wrong.
>

I actually did it differently, there's no point in them being both
IEquatable, it's sufficient for x to be IEquatable of y, and it's what I did
in the code.


>
> > In any case, I'm not sure we're still supporting .NET 1.x, in that case
> this
> > would go under a pre-processing direct
>
> We are in 2.6, so put it all under #if CLR_2_0 || CLR_4_0.
>

I committed the changes by branching the trunk, not sure it is correct. They
are in my branch so you can take a look.


>
> Charlie
> _____________
> > Mailing list: https://launchpad.net/~nunit-dev
> > Post to     : nunit-dev@xxxxxxxxxxxxxxxxxxx
> > Unsubscribe : https://launchpad.net/~nunit-dev
> > More help   : https://help.launchpad.net/ListHelp
> >
> >
>

Follow ups

References