-
-
Notifications
You must be signed in to change notification settings - Fork 197
Overriding Equals
Greg Finzer edited this page Aug 29, 2023
·
3 revisions
If you are going to have a base object and overriding equals you can easily create a stack overflow exception if you forget to set the Config.UseHashCodeIdentifier = true
`public class MyLovelyBaseClass { public override bool Equals(object? obj) { if (obj == null || this.GetType() != obj.GetType()) return false; MyLovelyBaseClass demo = (MyLovelyBaseClass)obj; return Compare(demo, this); }
public override int GetHashCode()
{
return base.GetHashCode();
}
private bool Compare(object object1, object object2)
{
CompareLogic compareLogic = new CompareLogic();
compareLogic.Config.UseHashCodeIdentifier = true;
ComparisonResult result = compareLogic.Compare(object1, object2);
return result.AreEqual;
}
}`