How extension methods are implemented internally

2020-02-12 05:22发布

How are extension methods implemented internally? I mean what happens when the compiler sees a declaration for an extension method and what happens at runtime when there is a call to an extension method.

Is reflection involved? Or when you have an extension method is its code injected in the target class type metadata with some additional flags noting that this is an extension method and then the CLR knows how to handle that?

So in general, what happens under the hood?

标签: c# .net clr
7条回答
叼着烟拽天下
2楼-- · 2020-02-12 05:59

extension methods are converted to static functions.In other words,They are syntactic sugar for static functions.

查看更多
登录 后发表回答