Me As Child Type In General Function
Posted
by Steven
on Stack Overflow
See other posts from Stack Overflow
or by Steven
Published on 2010-04-15T20:13:03Z
Indexed on
2010/04/15
21:13 UTC
Read the original article
Hit count: 228
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
© Stack Overflow or respective owner