I need to write a generic method in the base class that would accept 2 objects as parameters and compares them for equality.
Ex:
public abstract cla
Here's what I came up with using reflection. Hope it helps.
public bool AreEqual(object obj)
{
bool returnVal = true;
if (this.GetType() == obj.GetType())
{
FieldInfo[] fields = this.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
foreach (FieldInfo field in fields)
{
if(field.GetValue(this) != field.GetValue(obj))
{
returnVal = false;
break;
}
}
}
else
returnVal = false;
return returnVal;
}