Is it possible to overwrite instance methods by an extension-methods? For example, I have an assembly (compiled, without sources) and I want to rewrite some behaviour.
I created some code for test:
public class SomeClass
{
public void MyMethod()
{
Console.WriteLine("Instance method is called");
}
}
public static class ExtMethods
{
public static void MyMethod(this SomeClass c)
{
Console.WriteLine("Extention method is called");
}
}
then I try to use:
SomeClass s = new SomeClass();
s.MyMethod();
It's compiled successfully, IntelliSence marks this method as instance (extension method has another icon)
output says
Instance method is called
none note about extention method exists. So, no way to overwrite instance method, right?
Why the behavior of the compiler and VS is such non-informative? If I develop an extension-method and there exists already the same instance method (and I don't know about it), I can spend hours to understand why behavior is different than expected...