Tomas Pajonk
Tomas Pajonk

Reputation: 5202

Can I use Extension Methods to implement an Interface?

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 ?

Upvotes: 6

Views: 2122

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500525

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.

Upvotes: 13

Related Questions