MudassarRasool / mb-unit

Automatically exported from code.google.com/p/mb-unit
0 stars 0 forks source link

Equality Contract to support multiple implementations of IEquatable<T> with **unrelated** T's. #738

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Ref. 
http://groups.google.com/group/gallio-user/browse_thread/thread/144253d7be3efd43

The following scenario should be supported:

public class Foo : IEquatable<Foo>, IEquatable<string>
{
    private readonly string text;

    public string Text
    {
        get
        {
            return text;
        }
    }

    public Foo(string text)
    {
        this.text = text;
    }

    public override bool Equals(object obj)
    {
        return Equals(obj as Foo) || Equals(obj as string);
    }

    public override int GetHashCode()
    {
        return text.GetHashCode();
    }

    public bool Equals(Foo other)
    {
        return (other != null) && (other.text == text);
    }

    public bool Equals(string other)
    {
        return (other != null) && (other == text);
    }
}

Foo implements equality interfaces for 2 unrelated objects (Foo and 
System.String). The fact that Foo and System.String do not derive from each 
other is causing troubles when binding the equivalence classes.

Original issue reported on code.google.com by Yann.Tre...@gmail.com on 29 Sep 2010 at 6:32

GoogleCodeExporter commented 8 years ago

Original comment by Yann.Tre...@gmail.com on 3 Oct 2010 at 1:35