What's the best way to compare 2 versions of the same object and return a list of differences (name of property, old value and new value) See object graph below for an example. What if there was a change in the Product name how would I bubble that up into a list of property differences?
static void Main(string[] args)
{
Customer c1 = new Customer();
c1.DBA = "Test1";
c1.LatestOrder.DateOrdered = new DateTime(2011, 7, 12);
c1.LatestOrder.OrderDetails.Product = "Product1";
Customer c2 = new Customer();
c2.DBA = "Test1";
c2.LatestOrder.DateOrdered = new DateTime(2011, 7, 12);
c2.LatestOrder.OrderDetails.Product = "Product2";
}
So the test above shows that everything in the 2 objects are the same except for the product name. Maybe, just as proof of concept, a list showing the property name, old value and new value.
public class Customer
{
public string DBA { get; set; }
public Order LatestOrder { get; set; }
public Customer()
{
LatestOrder = new Order();
}
}
public class Order
{
public int Id { get; set; }
public DateTime DateOrdered { get; set; }
public OrderDetails OrderDetails { get; set; }
public Order()
{
OrderDetails = new OrderDetails();
}
}
public class OrderDetails
{
public String Product { get; set; }
}
}