using System.Linq; namespace jive { public class ValueType { public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; if (!(obj is ValueType)) return false; return Equals((ValueType) obj); } public bool Equals(ValueType other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return PropertiesMatch(other); } bool PropertiesMatch(ValueType other) { return !GetType().GetProperties().Any(x => { var thisValue = x.GetValue(this, null); var otherValue = x.GetValue(other, null); return !thisValue.Equals(otherValue); }); } public override int GetHashCode() { return GetType().GetProperties().Aggregate(0, (prev, prop) => (prev*397) ^ prop.GetHashCode()); } } }