Skip to content

Instantly share code, notes, and snippets.

@vmeln
Created March 24, 2014 09:31
Show Gist options
  • Save vmeln/9737130 to your computer and use it in GitHub Desktop.
Save vmeln/9737130 to your computer and use it in GitHub Desktop.
using System;
using System.Reflection;
namespace CompareProperties
{
class Program
{
static void Main(string[] args)
{
var object1 = new MyObject { Bool = false, Integer = 42, Long = 13 };
var object2 = new MyObject { Bool = false, Integer = 47, Long = 13 };
foreach (var prop in object1.GetType().GetProperties())
{
var lhs = prop.GetValue(object1);
var rhs = prop.GetValue(object2);
if (!lhs.Equals(rhs))
{
Console.WriteLine("{0} vs {1}", prop.GetValue(object1), prop.GetValue(object2));
Console.WriteLine("Values mismatching in: " + prop.Name);
}
}
}
}
public class MyObject
{
public int Integer { get; set; }
public bool Bool { get; set; }
public long Long { get; set; }
}
}
@vmeln
Copy link
Author

vmeln commented Mar 24, 2014

TODO: Refactor with generics and interfaces. Add collection change tracker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment