Skip to content

Instantly share code, notes, and snippets.

@butaji
Created January 31, 2011 20:12
Show Gist options
  • Save butaji/804714 to your computer and use it in GitHub Desktop.
Save butaji/804714 to your computer and use it in GitHub Desktop.
public Dictionary<string, object[]> CompareObjects<T>(T obj1, T obj2)
{
var result = new Dictionary<string, object[]>();
typeof(T)
.GetProperties()
.Select(p => new { p.Name, Val1 = p.GetValue(obj1, new object[] { }), Val2 = p.GetValue(obj2, new object[] { }) })
.Where(i => i.Val1 != i.Val2)
.ToList()
.ForEach(p => result.Add(p.Name, new[] { p.Val1, p.Val2 }));
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment