, .
, CLR .
IL.
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!!"));
........
}
IL.
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
, .
, .
, , , CompilerServices.ExtensionAttribute.