Permanenetly change type of object in VB.NET
<p>I have the following:</p>

<pre><code>Public Class OldClass
    Inherits NewClass
    ....
End Class
</code></pre>

<p><code>NewClass</code> Inherits from <code>BaseClass</code></p>

<p>Now I have a <code>list(Of BaseClass)</code></p>

<p>I am deserializing a few of these objects from XML. The XML could contain both <code>OldCLass</code>es and <code>NewCLass</code>es.</p>

<p>After deserialization the objects are in the list.</p>

<p><code>OldClass</code> is <em>exactly</em> the same as <code>NewClass</code> (the only code in <code>OldClass</code> is <code>Inherits NewClass</code>). I had to create the old class because the element name changed in the XML and I need to maintain backwards compatibility.</p>

<p>How can I permanently change the type of any <code>OldClass</code> objects in the <code>list</code> so that when they are re-serialized, they become <code>&lt;NewClass ...&gt;</code> instead of <code>&lt;OldClass ...&gt;</code>?</p>

<p>I have tried <code>CType</code>, <code>OldClass.ChangeType</code>, <code>list(list.indexOf(OldTypeObj)).ChangeType(...)</code>... Nothing works. When debugging, inspecting the list shows that the <code>OldClass</code>es are still just that.</p>

<p><strong>EDIT</strong></p>

<p>I am using this to serialize the existing data:</p>

<pre><code>&lt;XmlArray("lines")&gt; _
&lt;XmlArrayItem("CalculatedLine", GetType(Lines.CalculatedLine))&gt; _
&lt;XmlArrayItem("PointLine", GetType(Lines.PointLine))&gt; _
&lt;XmlArrayItem("line", GetType(Lines.OldLine))&gt; _ &lt;&lt;This needs to become PointLine when serialized.
Public Property lines As List(Of Lines.Line) = New List(Of Lines.Line)
</code></pre>