Reputation: 28294
I have an abstract class in VB.NET. I want all classes that inherit from this class to return whatever value makes sense. For example, it could be an Decimal, Integer, String. How can I delcare the function in the abstract base class to allow for this? Is this even possible?
Right now, my abstract class looks like this:
Public MustInherit Class ConversionBaseClass
Public MustOverride Function GetConvertedObject()
End Class
I know its return value needs modified, but im not sure as to what. Something like this maybe?
Public MustOverride Function GetConvertedObject() Of (T)
Upvotes: 0
Views: 1609
Reputation: 18474
Make the Base class be generic of T then you can use it for the method
Public MustInherit Class ConversionBaseClass (Of T)
Public MustOverride Function GetConvertedObject() As T
End Class
Then you define your inheriting classes like
public Class IntConversion Inherits ConversionBaseClass(Of Integer)
Public Overrides Function GetConvertedObject() As Integer
Upvotes: 2
Reputation: 67380
Public MustOverride Function GetConvertedObject(Of T)() As T
should do it.
Upvotes: 5