Reputation: 842
Is there any way of implementing IEqualityComparer for generic class?
I tried:
public class MyComparer : IEqualityComparer<MyGenericClass>
which is wrong, because MyGenericClass takes 3 arguments as a generics, so next one
public class MyComparer : IEqualityComparer<MyGenericClass<A, B, C>>
which is wrong, because I don't know types A,B,C. And so
public class MyComparer<MyGenericClass<A, B, C>> : IEqualityComparer<MyGenericClass<A, B, C>>
is wrong. Is there a way of implementing this? Thanks
Upvotes: 0
Views: 429
Reputation: 17307
You are close
public class MyComparer<A, B, C> : IEqualityComparer<MyGenericClass<A, B, C>>
Side note, please don't name things A, B, and C. That doesn't help anyone. Standard naming convention is T<SomethingDescriptive>
. In the case of EF, it might be TEntity
, in MVC or MVVM, it might be TModel
or TViewModel
.
Upvotes: 6