see also Hows to quick check if data transfer two objects have equal properties in C#?
I have lot of Data Transfer Objects (DTO) that each contains lots of simple fields. I need to implement Equals on all of them (so I can write some unit tests off transporting them var WCF).
The code I am using is:
public override bool Equals(object rhs)
{
RequestArguments other = rhs as RequestArguments;
return
other != null &&
other.m_RequestId.Equals(RequestId) &&
other.m_Type.Equals(m_Type) &&
other.m_Parameters.Equals(m_Parameters) &&
other.m_user.Equals(m_user);
}
There must be a better way!... (listing all the fields is rather asking for errors and maintenance problems)
E.g. we have Object. MemberwiseClone() to help with the Cloning() case, but I cannot find anything to help with Equals. We are running in full trust so a reflection based solution is one answer, but I rather not reinvent the wheel.
(Sorry we don’t generate the DTO from a domain-specific language otherwise this sort of thing would be easy! Also I am not able to change the build system to add another step)