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

List value need not be in same order for equality check #53

Closed NaveenkumarIyappan closed 11 months ago

NaveenkumarIyappan commented 1 year ago

This library works great for most cases, but when comparing a List the elements are required be in the same order. Ex:

List<string>{"cat","dog"}
List<string>{"dog","cat"}

this says there is a difference. But this should return no difference. Is this a limitation in the library or if there a way to impose this check, how can it be done?

reponemec commented 1 year ago

This appears to be intentional and so far the only behavior. However, there is at least a #47 PR that has this and a number of other things already done.

[Test]
public void CompareListByKey()
{
    var a1 = new List<string> { "cat", "dog" };
    var a2 = new List<string> { "dog", "cat" };

    var settings = new ComparisonSettings();
    settings.ConfigureListComparison(compareElementsByKey: true);
    var comparer = new Comparer(settings);
    var differences = comparer.CalculateDifferences(a1, a2).ToArray();

    Assert.IsTrue(differences.Count() == 0);
}
NaveenkumarIyappan commented 1 year ago

I appreciate it. Thank you for the prompt response.