W
Will Lusted
Can anyone give me a pointer as where I'm going wrong?
I'm building a base class that persists to a database using serialization.
GetDoc() is a base class function that reads back XML to deserialize into a
new instance.
The derived class needs to convert the resultant object into an instance of
itself -
or at least it would do except I can't get GetType to return a reference to
the current running type to cast the object:
Public Function GetDoc(ByVal ID As Decimal)
Dim xs As XmlSerializer
Dim rdr As StringReader = Me.ReadDBString(ID)
Dim obj As Object
Try
xs = New XmlSerializer(Me.GetType)
obj = xs.Deserialize(rdr)
Dim MyType As Type = Me.GetType
Return DirectCast(obj, mytype) ' fails
miserable, compile error mytype not defined
Catch ex As Exception
ErrorLog.Add(ex)
Finally
xs = Nothing
rdr = Nothing
End Try
End Function
I know this should be possible, but I'm obviously missing a trick. Any
constructive suggestions would be welcome, and thanks in advance.
Will Lusted
I'm building a base class that persists to a database using serialization.
GetDoc() is a base class function that reads back XML to deserialize into a
new instance.
The derived class needs to convert the resultant object into an instance of
itself -
or at least it would do except I can't get GetType to return a reference to
the current running type to cast the object:
Public Function GetDoc(ByVal ID As Decimal)
Dim xs As XmlSerializer
Dim rdr As StringReader = Me.ReadDBString(ID)
Dim obj As Object
Try
xs = New XmlSerializer(Me.GetType)
obj = xs.Deserialize(rdr)
Dim MyType As Type = Me.GetType
Return DirectCast(obj, mytype) ' fails
miserable, compile error mytype not defined
Catch ex As Exception
ErrorLog.Add(ex)
Finally
xs = Nothing
rdr = Nothing
End Try
End Function
I know this should be possible, but I'm obviously missing a trick. Any
constructive suggestions would be welcome, and thanks in advance.
Will Lusted