We scaffolded database from Entity Framework to create class models. We have over 1000 classes. Now we're implementing unit tests, to compare classes inserting an Actual class with Expected class. The following website recommends method below to compare all Members.
Do I have to write this for all my 1000+ classes? Or is there a way to use auto code generate in Visual Studio to create all these IEquatable? Maybe with T4?
https://grantwinney.com/how-to-compare-two-objects-testing-for-equality-in-c/
public class Person : IEquatable<Person>
{
public string Name { get; set; }
public int Age { get; set; }
public bool Equals(Person other)
{
if (ReferenceEquals(other, null))
return false;
if (ReferenceEquals(this, other))
return true;
return Name.Equals(other.Name) && Age.Equals(other.Age);
}
Teamwork Guy answer below is nice, need to way to implement this kind of method for 1000+ classes.