I need to make a comparison between two techniques : Use of generic type and extend type. I don't mean a general comparison, I mean in this specific case when I need to add some features to a class named ClassA
Using a generic type
use a generic type (
Where T: ClassA
) and implement generic methodsUsing Extension Methods
Use the
ClassA
by adding its extension methodspublic static class Helper { public static void MethodOne(this ClassA obj, ) { // } }
I need to know :
- What are the advantages of each technique in comparison with the other?
- Why the first technique is always used in
Repository Pattern
? For example in this implementation why we don't add extension methods to a global classEntity
?