XML Serialization & Deserialization
-
Hi all I am looking at XML Serialization at the moment, most of it is pretty straight forward [so far]. I am after creating my own employee class that I am configuring for XML serialization, 1. declaring it as a Public class, 2. making all necessary variables Public and 3. adding a Parameterless constructor. When I was looking into BinaryFormatter and SoapFormatter, to handle Deserialization I had to implement the interface IDeserializationCallback and then create a method that implements IDeserializationCallback.OnDeserialization to populate any temporary variables. How do I do this with XML Serialization? The example I've seen in the book for MCTS exam 70-536 shows that you take your employee class and add the serializable attribute to it and implement IDeserializationCallback. You then use the attribute NonSerialized to mark a type that is not to be serialized. Michael.
-
Hi all I am looking at XML Serialization at the moment, most of it is pretty straight forward [so far]. I am after creating my own employee class that I am configuring for XML serialization, 1. declaring it as a Public class, 2. making all necessary variables Public and 3. adding a Parameterless constructor. When I was looking into BinaryFormatter and SoapFormatter, to handle Deserialization I had to implement the interface IDeserializationCallback and then create a method that implements IDeserializationCallback.OnDeserialization to populate any temporary variables. How do I do this with XML Serialization? The example I've seen in the book for MCTS exam 70-536 shows that you take your employee class and add the serializable attribute to it and implement IDeserializationCallback. You then use the attribute NonSerialized to mark a type that is not to be serialized. Michael.
mike123543 wrote:
The example I've seen in the book for MCTS exam 70-536 shows that you take your employee class and add the serializable attribute to it and implement IDeserializationCallback. You then use the attribute NonSerialized to mark a type that is not to be serialized
And have you tried that?
Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.
-
mike123543 wrote:
The example I've seen in the book for MCTS exam 70-536 shows that you take your employee class and add the serializable attribute to it and implement IDeserializationCallback. You then use the attribute NonSerialized to mark a type that is not to be serialized
And have you tried that?
Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.
IDeserializationCallback does not seem to be available to me when using XML serialization. It would appear to be only available to SoapFormatter, BinaryFormatter or when completing Custom Serialization. This issue would only arise if I needed to customise the xml serialization, I can always rely on the standard Custom Serialization. Michael.
-
IDeserializationCallback does not seem to be available to me when using XML serialization. It would appear to be only available to SoapFormatter, BinaryFormatter or when completing Custom Serialization. This issue would only arise if I needed to customise the xml serialization, I can always rely on the standard Custom Serialization. Michael.
mike123543 wrote:
This issue would only arise if I needed to customise the xml serialization
This is true. Try this book, Chapter 7 to start[^] It is really thorough.
Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.