DeepEqual icon indicating copy to clipboard operation
DeepEqual copied to clipboard

Comparing dictionaries containing classes is problematic

Open rsandila opened this issue 4 years ago • 1 comments

When running the provided code the IsDeepEqual call consumes more than 1 GB of memory and had to be stopped after 1 minute.

using System;
using System.Collections.Generic;
using DeepEqual.Syntax;

namespace test1
{
    class Test
    {
        public string A { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var object1 = new Dictionary<int, Test>();
            var object2 = new Dictionary<int, Test>();
            for (int c = 0; c < 100; c++)
            {
                object1.Add(c, new Test { A = c.ToString() });
                object2.Add(c, new Test { A = c.ToString() });
            }

            object2[10].A = "different";
            Console.WriteLine($"Equals: {object1.IsDeepEqual(object2)}");
        }
    }
}

This happens under .NET Core 3.1 and .NET 5 using version 2.0.0

rsandila avatar Sep 14 '21 19:09 rsandila

A usable workaround seems to be object1.ToList().IsDeepEqual(object2.ToList())

rsandila avatar Sep 14 '21 19:09 rsandila

I believe this is fixed in the latest version. Please let me know if it's not.

jamesfoster avatar Aug 20 '22 13:08 jamesfoster