How do extension methods work under-the-hood?

后端 未结 6 1106
半阙折子戏
半阙折子戏 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:38

    I assume extension methods make heavy use of reflection (which is slower).

    No. Extension methods are resolved at compile-time, no reflection required.
    That negates your performance concerns.

    Is it better to use inheretance or extension methods ?

    I would say neither. Use a Repository (DAL). An entity should be persistence-agnostic (so: no inheritance from a base that does CRUD) and not pretend to be involved where it's not (no extensions).

    You are right that "Using extension methods obfuscates & confuses the source of the CRUD methods" but inheritance is not the solution.

提交回复
热议问题