Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use Extension Methods to implement an Interface?

Tags:

c#

.net

I would like a class to implement an interface, I do not want to change the original class (that would add undesired dependecies).

I know I could inherit from the class and make it's child implement these methods, but then I am faced with a problem how to convert the parent class (that come from the data / ORM) to this presentation class.

If I implement all the interface required methods, will it count as being that interface or not ?

like image 779
Tomas Pajonk Avatar asked Nov 25 '08 11:11

Tomas Pajonk


1 Answers

No, it still won't count as implementing the interface.

Extension methods are nothing more than a way of calling static methods in a different kind of way. They don't affect object identity, inheritance etc at all.

like image 142
Jon Skeet Avatar answered Oct 27 '22 01:10

Jon Skeet