C
C#16mo 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
}
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; }
}
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
3 Replies
phaseshift
phaseshift16mo ago
GitHub
GitHub - GregFinzer/Compare-Net-Objects: What you have been waiting...
What you have been waiting for :+1: Perform a deep compare of any two .NET objects using reflection. Shows the differences between the two objects. - GitHub - GregFinzer/Compare-Net-Objects: What...
Buffdude1100
Buffdude110016mo ago
https://github.com/wbish/jsondiffpatch.net Convert both to json and you can generate a diff
GitHub
GitHub - wbish/jsondiffpatch.net: JSON object diffs and reversible ...
JSON object diffs and reversible patching (jsondiffpatch compatible) - GitHub - wbish/jsondiffpatch.net: JSON object diffs and reversible patching (jsondiffpatch compatible)
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server