I am repeating myself, and violating DRY. What I need is a base class that implements the operator == and != and GetHashCode and Equals. The base class must list all properties (through reflection?) of the top most derived class. And compare these properties in these operator functions, or combine their hashcodes in GetHashCode.
Example pseudo code:
public static Boolean operator == (KeyValue A, KeyValue B)
{
List<PropertiesOfKeyValueClass> Properties = Reflection.GetProperties(KeyValue);
foreach (Property prop in Properties)
{
if (A.prop != B.Prop) return false;
}
}
I can't imagine this isn't implemented in the .Net framework already, but I can't find it. So instead of 'inventing the wheel' I thought I could ask on StackOverflow first.