I have a MustInherit
Parent class with two Child classes which Inherit from the Parent.
How can I use (or Cast) Me
in a Parent function as the the child type of that instance?
EDIT: My actual goal is to be able to serialize (BinaryFormatter.Serialize(Stream, Object)
) either of my child classes. However, "repeating the code" in each child "seems" wrong.
EDIT2: This is my Serialize function. Where should I implement this function? Copying and pasting to each child doesn't seem right, but casting the parent to a child doesn't seem right either.
Public Function Serialize() As Byte()
Dim bFmt As New BinaryFormatter()
Dim mStr As New MemoryStream()
bFmt.Serialize(mStr, Me)
Return mStr.ToArray()
End Function