In C#, the "this" reference is implicitly used when invoking methods of a class. The same does not seem to hold when using extension methods:
public static class TestExtensions
{
public static void ExtensionMethod(this Test t)
{
// IMPLEMENTATION
}
}
public class Test
{
public void A()
{
B(); // implicitly this.B();
}
public void B()
{
ExtensionMethod(); // doesn't work!
this.ExtensionMethod(); // works!
}
}
I understand that extension methods are merely "sugar" that passes the "this" reference into the statis extension method. But why should it enforce also adding the "this" keyword, if it can find the method to invoke anyway ?