P
pamela fluente
I have a question: either a C# or VB answer is perfectly fine. I want
to know if there is a way to tell a class that there is an inheritance
relationship between the type parameters.
I have a complex situation, but to make it easy I have reduced the
problem to the very essence.
Here is my simple example (vb syntax):
------------------------------------
Class ParentType
End Class
Class DerivedType
Inherits ParentType
End Class
Class AnyType
End Class
Class Example(Of AnyType, DerivedType, ParentType)
Public P As ParentType
Function GetChild() As DerivedType
Return DirectCast(P, DerivedType)
End Function
End Class
------------------------------------
The point here is that the instruction
DirectCast(P, DerivedType)
would be ok if I had a way to "inform" the class Class Example(Of
DerivedType, ParentType) that
"DerivedType" will be inheriting "ParentType".
(for instance, this would be remarkably useful to avoid casting when
using "GetChild" class.)
How can I do that?
-P
to know if there is a way to tell a class that there is an inheritance
relationship between the type parameters.
I have a complex situation, but to make it easy I have reduced the
problem to the very essence.
Here is my simple example (vb syntax):
------------------------------------
Class ParentType
End Class
Class DerivedType
Inherits ParentType
End Class
Class AnyType
End Class
Class Example(Of AnyType, DerivedType, ParentType)
Public P As ParentType
Function GetChild() As DerivedType
Return DirectCast(P, DerivedType)
End Function
End Class
------------------------------------
The point here is that the instruction
DirectCast(P, DerivedType)
would be ok if I had a way to "inform" the class Class Example(Of
DerivedType, ParentType) that
"DerivedType" will be inheriting "ParentType".
(for instance, this would be remarkably useful to avoid casting when
using "GetChild" class.)
How can I do that?
-P