是否有可能通過引用包含擴展方法的名稱空間將代碼注入到類中,從而模擬某些接口的基類實現?或者這被認爲是不好的做法(即使這是不可能的)?'使用擴展方法將'注入'類實現並因此實現接口?
Imports MyApp.Extensions
Class SomeClass : Inherits System.SomeBaseClass : Implements MyApp.IAppInterface
End Class
Public Interface IAppInterface
Sub InterfaceMethod()
End Interface
Namespace MyApp.Extensions
Public Module SomeClassExtensions
Public Sub InterfaceMethod(ByVal someClass as MyApp.SomeClass)
//Implementation
End Sub
End Module
End Namespace
不,這是不可能的。 – Josh 2011-01-30 18:44:15