C
Charles Law
Two questions really:
1. Can an object de-serialise itself?
I use XMLSerializer and the Deserialize method to read an XML file and
return an object of my given type. The code that does this then returns the
new object to the caller.
<code>
Dim serializer As New XmlSerializer(GetType(MyType))
fs = New FileStream(filename, FileMode.Open)
return CType(serializer.Deserialize(fs), MyType)
</code>
I would prefer to create a new object of type MyType and then call a method
of MyType to de-serialise it. Is this possible?
2. Is there an event that is raised when de-serialisation is complete?
In the above scenario, I need to perform some initialisation of the new
MyType object, but after it has been de-serialised. Is there an event that I
can handle that is raised when de-serialisation is complete, or, better
still, is there a method that I can implement in MyType that will get called
automatically?
TIA
Charles
1. Can an object de-serialise itself?
I use XMLSerializer and the Deserialize method to read an XML file and
return an object of my given type. The code that does this then returns the
new object to the caller.
<code>
Dim serializer As New XmlSerializer(GetType(MyType))
fs = New FileStream(filename, FileMode.Open)
return CType(serializer.Deserialize(fs), MyType)
</code>
I would prefer to create a new object of type MyType and then call a method
of MyType to de-serialise it. Is this possible?
2. Is there an event that is raised when de-serialisation is complete?
In the above scenario, I need to perform some initialisation of the new
MyType object, but after it has been de-serialised. Is there an event that I
can handle that is raised when de-serialisation is complete, or, better
still, is there a method that I can implement in MyType that will get called
automatically?
TIA
Charles