ValeraT1982 / ObjectsComparer

C# Framework provides mechanism to compare complex objects, allows to override comparison rules for specific properties and types.
MIT License
352 stars 86 forks source link

Class with IList<Uri> throws AmbiguousComparerOverrideResolutionException #40

Closed DCourtel closed 2 years ago

DCourtel commented 2 years ago

A class like this:

public class TestClass
{
    public IList<Uri> Urls { get; } = new List<Uri>();
}

Throws an AmbiguousComparerOverrideResolutionException when compared with this code:

public void CompareTestClass()
{
    var obj1 = new TestClass();
    obj1.Urls.Add(new Uri("https://Test.com"));
    var obj2 = new TestClass();
    obj2.Urls.Add(new Uri("https://Test.com"));

    var comparer = new ObjectsComparer.Comparer<TestClass>();
    //  comparer.AddComparerOverride<IList<Uri>>(new ListOfUriComparer());
    IEnumerable<Difference> differences = new List<Difference>();
    comparer.Compare(obj1, obj2, out differences);
}

Uncommenting the line with the AddComparerOverride method solves the issue but the comparer should be able to compare list of Uri natively. Also, the error message is misleading:

Unable to resolve comparer for type System.Uri. More than one value comparer meet criteria for this type.

It should reference IList of Uri. Thanks.

ValeraT1982 commented 2 years ago

Fix submitted. Will be available in the next version.

DCourtel commented 2 years ago

Thanks.