可能重复:
Is there any way in C# to override a class method with an extension method?如何调用与现有方法同名的扩展方法?
我有这样的代码
public class TestA
{
public string ColA { get; set; }
public string ColB { get; set; }
public string ColC { get; set; }
public void MethodA()
{
MessageBox.Show("Original A1.");
}
}
static class ExtenstionTest
{
public static void MethodA(this TestA A1)
{
MessageBox.Show("Extended A1.");
}
}
现在,如果我叫治法像
TestA a = new TestA();
a.MethodA();
它将始终调用原始方法。我怎样才能调用扩展方法。
此外的轻微变化http://stackoverflow.com/questions/2303885/if-an-extension-method-has-the-same-signature-as-a-method-in-the-sealed- class-w?rq = 1 – 2012-11-23 07:25:47