I need to create a general method that will take two objects (of the same type) and return a list of properties that have different values. Since my requirement is a little different, I don't think it's like a 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>();
if(A.Age != B.Age)
{
}
..
..
return changedProperties;
}
The following should be considered:
- General - should be able to compare objects of any type (with the same class)
- Performance
- Plain
Are there any libraries out of the box?
Can I achieve this using AutoMapper ?
Rahul source
share