They are a language extension. As you suspected, the compiler is doing all the work and producing IL code that calls the extension method explicitly as a static method. This can be verified by looking at the IL.
IL_0000: newobj instance void Sandbox.Program/Foo::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: call void Sandbox.Program::Bar(class Sandbox.Program/Foo)
Here I defined a class Foo
and an extension method Bar()
and then called foo.Bar()
.
The dump of the Bar()
function shows it doesn't do anything special, except for the System.Runtime.CompilerServices.ExtensionAttribute
:
.method public hidebysig static void Bar(class Sandbox.Program/Foo foo) cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 )
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method Program::Bar