Created
March 24, 2014 09:31
-
-
Save vmeln/9737130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: Refactor with generics and interfaces. Add collection change tracker.