I need to create a generic method, which will take two objects (of same type), and return list of properties which have different values. As my requirement is bit different I don't think this as duplicate.
public class Person
{
public string Name {get;set;}
public string Age {get;set;}
}
Person p1 = new Person{FirstName = "David", Age = 33}
Person p2 = new Person{FirstName = "David", Age = 44}
var changedProperties = GetChangedProperties(p1,p2);
The code explains the requirement:
public List<string> GetChangedProperties(object A, object B)
{
List<string> changedProperties = new List<string>();
//Compare for changed values in properties
if(A.Age != B.Age)
{
//changedProperties.Add("Age");
}
//Compare other properties
..
..
return changedProperties;
}
Should consider following:
- Generic - Should be able to compare any type of objects (with same class)
- Performance
- Simple
Is there any libraries available out of the box there?
Can I achieve this using AutoMapper?