How do extension methods work under-the-hood?

后端 未结 6 1099
半阙折子戏
半阙折子戏 2021-02-13 12:56

A contractor where I work is using extension methods to implement CRUD on well-known internal classes that we own. I say it is better

6条回答
  •  广开言路
    2021-02-13 13:18

    Under the hood, an extension method is just like a regular method, and the object it's called on is passed as the first parameter (the this parameter). There's nothing special about an extension method, it's just syntax candy.

    It's good practice to avoid extension methods whenever you can. They make the code less readable and less object-oriented.

    If it's a class you own, I see no reason to add an extension method to it.

提交回复
热议问题