using System.Collections;
using System.Collections.Generic;
public static void Main()
var initalCourseState = new Course(){
Students = new List<Student>(){
new Student { Id = 1, FirstName = "Cheshire", LastName = "Cat" },
new Student { Id = 2, FirstName = "Mad", LastName = "Hatter" }
var updatedCourseState = new Course(){
Students = new List<Student>(){
new Student { Id = 4, FirstName = "Door", LastName = "Mouse" },
new Student { Id = 2, FirstName = "Mad", LastName = "Hatter" },
new Student { Id = 3, FirstName = "Alice", LastName = "Wonderland" }
var changes = initalCourseState.DetailedCompare(updatedCourseState);
foreach(var change in changes){ Console.WriteLine("Property: " + change.PropertyName + " has changed from '" + change.ValA + "' to '" + change.ValB + "'"); }
public int Id { get; set; }
public string RoomName { get; set; }
public int NumberOfDesks { get; set; }
public IEnumerable<Student> Students { get; set; }
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public static List<Variance> DetailedCompare<T>(this T val1, T val2){
var variances = new List<Variance>();
var properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach(var property in properties){
PropertyName = property.Name,
ValA = property.GetValue(val1, null),
ValB = property.GetValue(val2, null)
if(v.ValA == null && v.ValB == null) { continue; }
if(v.ValA != null && !v.ValA.Equals(v.ValB)){
public string PropertyName { get; set; }
public object ValA { get; set; }
public object ValB { get; set; }