Adds a matching criterion to the structural equality comparer.

Namespace:  MbUnit.Framework
Assembly:  MbUnit (in MbUnit.dll) Version: 3.3.0.0 (3.3.610.0)

Syntax

C#
public void Add(
	IEqualityComparer<T> comparer
)
Visual Basic (Declaration)
Public Sub Add ( _
	comparer As IEqualityComparer(Of T) _
)

Parameters

comparer
Type: System.Collections.Generic..::.IEqualityComparer<(Of <(T>)>)
An comparer object to directly compare two instances, or null to use the default one.

Remarks

The evaluation process is done through the specified comparer object.

Examples

CopyC#
public class Foo
{
    public int Value;
}

public class MyComparer : IEqualityComparer<Foo>
{
    public bool Equals(Foo x, Foo y)
    {
        return x.Value == y.Value;    
    }

    public int GetHashCode(int obj)
    {
        return obj;
    }
}

[TestFixture]
public class FooTest
{
    [Test]
    public void MyTest()
    {
        var foo1 = new Foo() { Value = 123 };    
        var foo2 = new Foo() { Value = 123 };

        Assert.AreEqual(foo1, foo2, new StructuralEqualityComparer<Foo>
        {
            { new MyComparer() },
        });
    }
}

See Also