Accessing new object before XmlSerializer.Deserialize completes
Hello, the XmlSerializer class is great but it seems like it's lacking one
very important feature... the ability for the caller to access the newly
created object prior to finishing deserialization. What if you were
deserializing in xml but you needed access to a dependency in order to
perform the deserialization.
Here's an example of a class that needs to look up a resource based on the
ID it receives during deserialization but there's no way to set the
Resources property first.
Public Class Class1
Implements Xml.Serialization.IXmlSerializable
Public ResourceValue As Object
Public Resources As Hashtable ' this needs to be passed in before
ReadXml can be called
Public Sub ReadXml(ByVal reader As System.Xml.XmlReader) Implements
System.Xml.Serialization.IXmlSerializable.ReadXml
Dim ResourceId As String = reader.ReadElementString
ResourceValue = Resources(ResourceId)
End Sub
...etc...
End Class
XmlSerializer only supports passing in a type but not constructor args nor
does it raise a BeforeDeserialize(NewObject) event. Can anyone else confirm
that this is simply not possible? It seems like it would have been really
easy for MS to add support for this but just didn't.
-- Tim
|