As already have said by other colleagues it is just a static method.
It is all about the compiler we can say that CLR even have no idea about extension methods.
You can try to check IL code ..
Here is an example
static class ExtendedString
{
public static String TestMethod(this String str, String someParam)
{
return someParam;
}
}
static void Main(string[] args)
{
String str = String.Empty;
Console.WriteLine(str.TestMethod("Hello World!!"));
........
}
And here is the IL code.
IL_0001: ldsfld string [mscorlib]System.String::Empty
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: ldstr "Hello World!!"
IL_000d: call string StringPooling.ExtendedString::TestMethod(string,
string)
IL_0012: call void [mscorlib]System.Console::WriteLine(string)
IL_0017: nop
As you can see it is just a call of static method.
The method is not added to the class, but compiler makes it look like that.
And on reflection layer the only difference you can see is that CompilerServices.ExtensionAttribute is added.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…