C#C
C#3y ago
Alizer

❔ I need help making a `diff` of 2 objects of the same class

I have a complex class like below
public class Person {
  public string Name { get; set; }

  public byte Age { get; set; }

  public List<Person>? Children { get; set; }

// many other properties omitted
}

Now, I have 2 instances of this class Person and I want to get the differences between both, my problem is the Person class is a really complex class, it has around 20+ properties, some properties are collections, I made a class like below to record the differences
public class Difference {
  public string PropertyPath { get; set; }

  public object OriginalValue { get; set; }

  public object NewValue { get; set; }
}

my question is, how do I start with this? if there is a library that does this automatically I would use it
Was this page helpful?