DynamiteXml is a lightweight serializing tool.
It stores the serialized type within the xml.
This way different processes can talk to an interface instead of an implementation.
Dynamite in DynamiteXml is:
* The power
* Not depending on external components.
(C#, .net 3.5)
When would you use DynamiteXml ?
Whenever you want to serialize an object to xml, yet on the other hand want to approach the object via an interface instead of the implementation.
Below are 2 situations that show the benefits:
Engine - plugin relation.
Say there's an engine with a UI showing the fields listed in IDisplayFields.
A plugin creates an object, implementing the IDisplayFields amongst other logic.
The object is stored in a database, in xml. For that it needs to be serialized.
When the engine loads the object, it does not want to know what object it is, it only cares whether it implements IDisplayFields or not.
How DynamiteXml can help you:
If you make sure that the object implements IDynamiteXml (Just a naming interface),
logic in the DynamiteXml assembly can serialize and deserialize the object automatically.
The engine simply asks DynamiteXml to restore the xml to IDisplayFields.
Under the hood, it is restored to the original type created by the plugin.
But the engine does not care about that.
Process to process communication (message queuing principle).
Website1 accepts Dutch address details.
Website2 accepts English address details.
Both store the information in a database.
The address data is too specific to store in regular columns, it will be stored as xml in this example.
A next process picks up newly uploaded addresses & wants to print labels.
For that it requires the various address objects to imlpement the IPrintAddress interface.
How DynamiteXml can help you:
To provide IPrintAddress functionality, the classes DutchAddress & EnglishAddress implement IPrintAddress.
For DynamiteXml to be able to return the object as IPrintAddress, this interface should extend from IDynamiteXml.
- To serialize DutchAddress & EnglishAddress, they need to implement IDynamiteXml. Since both implement IPrintAddress, IDynamiteXml is already implemented automatically.
Website1 can store the Dutch address by instantiating a DutchAddress class & serializing it using DynamiteXml.
Website2 can store the English address by instantiating an EnglishAddress class & serializing it using DynamiteXml.
The labels printing process can use DynamiteXml to deserialize the stored xml to an IPrintAddress-able object.
How do you use DynamiteXml ?
Example code is added to the source code, but in short:
- string myXml = DynamiteXmlLogic.Serialize(DutchAddress1);
And to deserialize the above:
- // Return IDynamiteXml, to be casted manually
- IDynamiteXml myXmlObject = DynamiteXmlLogic.Deserialize(myXml);
- // Return as IPrintAddress immediately, using a generic method
- IPrintAddress myXmlObject = DynamiteXmlLogic.Deserialize<IPrintAddress >(myXml);
What will the serialized data look like?
The generated xml after DynamiteXml serialized the object will look like:
<assembly>Assembly in which the serialized object is stored
<name>The fullname of the System.Type of the serialized object
The serialized data of the object.
Prerequisites to use DynamiteXml
- The DynamiteXml dll needs to be added to the project.
- .Net 3.5
- The accessibility of an object needs to be public to be serializeable (as always with xml serialization).
- Classes and interfaces that are serialized from or deserialized to by DynamiteXml need to implement the IDynamiteXml (naming) interface.
- Since DynamiteXml uses reflection, the assembly containing the type of the serialized object needs to be available.