thể trùng lặp:
Is there any way in C# to override a class method with an extension method?Làm thế nào để gọi phương thức mở rộng có cùng tên với một phương thức hiện có?
tôi có mã như
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.");
}
}
Bây giờ nếu tôi gọi MethodA như
TestA a = new TestA();
a.MethodA();
Nó sẽ luôn gọi phương thức gốc. Làm thế nào tôi có thể gọi phương thức mở rộng.
Cũng có một biến thể nhỏ http://stackoverflow.com/questions/2303885/if-an-extension-method-has-the-same-signature-as-a-method-in-the-sealed- class-w? rq = 1 –