1
代碼如下所示:
Public Class MasterA
Inherits Underling
End Class
Public Class MasterB
Inherits Underling
End Class
Public Mustinherit Class Underling
Sub DoSomething()
Me.GetType 'Using the instance, I can get the class.
end sub
Shared function() as ???? 'How can I define the return type based on the class that inherited me?
'Me.GetType 'Won't work as this is a shared function with no instance 'Me'
End Function
End class
確定。問題是:有沒有辦法從另一個類繼承的共享函數中獲取類類型?
我在構建的是一個XML序列化器/解析器作爲一個可繼承的類,以便繼承它的類可以被嵌套到一個XML文件中,然後再返回。我不想爲每種類型的類編寫序列化器/反序列化器,我只想繼承這些功能。
儘管如此,要求我能夠確定在共享函數中繼承我的clas。