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 class BaseData
{
public bool AreEqual(object O1, object O2)
{
//Need to implement this
}
}
public class DataTypeOne : BaseData
{
public string Name;
public string Address;
}
public class DataTypeTwo : BaseData
{
public int CustId;
public string CustName;
}
The AreEqual()
method would accept 2 instances of DataTypeOne
or 2 instances of DataTypeTwo
.
My guess is I need to use Reflection? I can use LINQ if it can be more readable/concise.
EDIT: The reason I would like to implement this method in the base class is because of project restrictions. There are a large number of devs working on the derived classes. By implementing this in the base class, I am trying to have 1 less thing for them to worry about.