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

ICollection<object> values aren't being compared #23

Closed rbeesley closed 3 years ago

rbeesley commented 3 years ago
            var expected = new List<object> {
                1,
                "2"
            };

            var actual = new List<object> {
                1,
                "3"
            };

            var comparer = new ObjectsComparer.Comparer();
            IEnumerable<Difference> differences;

            comparer.Compare(expected, actual, out differences);

I expected Compare to return a false. If I change the type of objects to List and use integers or if I change the type to List and use strings it will see the differences, but I have an ICollection, IList or IDictionary, which can consist of different primitives or ICollection types and I'm trying to find a way to verify that the potentially deeply nested values are the same.

ValeraT1982 commented 3 years ago

@rbeesley, it's an expected behavior. If you specify type of the elements as an object then comparer compare elements by properties declared in object.

In this case probably the best solution would be to convert all elements to sting and then compare as List.