I have the following class and I've two object of it,Obj1 one have the previous data and obj2 have the data with some fields that can be changed (Im in action of edit which have obj1 before changing and obj2 after).my question is if I have the two object how is the best way to put in object (like list of key val) just the fields that was changed and they value. I read about it in the SO and I found this two approach but some of the post are old..., what is right/efficient way to go ?example will be very helpful.
Get the changed properties in same object
public class UserData
{
public int Id { get; set; }
public string UserName { get; set; }
public string Address { get; set; }
public string Email { get; set; }
public string Work { get; set; }
public string Home { get; set; }
}
public class Program
{
public static void Main()
{
UserData obj1 = new UserData();
obj1.Email = "www.test.com";
obj1.Home = "test home";
UserData obj2 = new UserData();
obj2.Email = "www.test2.com";
obj2.Home = "test home2";
}
}
I've tried like the following from this post but I got error,any idea? Compare two objects and find the differences
changedList = obj1.DetailedCompare(obj2);
I got this error,any idea how to solve it:
The type arguments for method
'Web.Controllers.extentions.DetailedCompare<T>(T, T)'
cannot be inferred from the usage. Try specifying the type arguments explicitly