Create Record type.
public record Animal
{
public string Name{ get; init; }
public string Type{ get; init; }
public string Genus{ get; init; }
public string Owner { get; init; }
}
var cat= new Animal
{
Name = "FluffyCat",
Type = "Feline",
Genus = "Mammal",
Owner = "Agent Smith"
};
Clone and change some values.
var newCat = cat with
{ Name = "AngryCat", Owner= "Morpheus" };
We can test for equality easily enough
Console.WriteLine(newCat.Equals(cat));
How can I find the changed values and property names without comparing every property value?
Not sure how you can check for changed properties without checking for changed values.
A LINQ query with Reflections can be used to see what property names no longer are the same. This is compact and does not need an if statement for each of the properties.
This will return a Dictionary of Keys and Values that are changed.