I have a number of data classes that have more than 25 properties of different types of values ββ(and this may change in the future as requirements change). I would like to redefine equal values, mainly for unit testing purposes.
Currently, the only way I know how to do this is to verify that each property is actually hardcoded. This seems bad for two reasons: firstly, I will need to write a lot of code to check 25 properties for equality - secondly, if a property is added in one of the classes later, the Equals method does not check this, and most likely it will remain undetected and lead to problems in the future.
Because Equals typically checks for class properties, there must be a way to dynamically compare the properties of the classes being compared, which ensures that the property modifies the class without leading to an incorrect implementation of Equals. Is there any way to do this?
source
share