I have a class Product : IProduct. All the code that uses products works with interfaces, interface implementation is supplied by an in-house DI container. What do I need to add to the interface and the class, so I can write code like:
IProduct defectiveSku;
IProduct customerSku;
….
if(customerSku == devectiveSku)
{
// refund, blame someone else
}
else
{
// scare the customer away
}
You can use the
IEquatable<T>interface:But you’ll have to compare with the
Equalsmethod:Comparing with
Equalsis better for an entity likeIProductbecause it better conveys the semantics of entity equality than the==operator; which normally conveys just reference equality or value equality.