Version 2.0
A PCL version of Blueprints 2.0 is now available via nuget. Source code and documentation will be updated soon.
Project Description
Blueprints is a .NET serializer with a graphical editor. Its polymorphism support makes it a good candidate for serializing and editing Dependency Injection configurations. It can also serialize data to multiple files by linking them.
Features:
- Allows polymorphism
- Allows linking to other blueprint documents
- Keeps object references in tact and allows circular references
- Supports custom constructors, via attributes or configuration file
- Allows (de)serialization of streaming elements
- Comes with an editor to edit and validate blueprints:
Blueprint Editor
I wanted to enable a form of depency injection through Xml configuration. However editing such a file is extremely hard - especially for a non-developer - from not knowing the available enum values to having to having to provide the AssemblyName for a injected type. And to make matters worse, errors would reveal themselves only when starting the application.
For applications using Blueprints as serializer, the BlueprintEditor solves this issue:
- Enum selection via a dropdown list or checkboxes (flags)
- A list of all compatible types shown when selecting a type
- Automatic validation of data against their data types
The editor has been my main focus for a long time, but even without the editor Blueprints is a complete serializer with powerful features.
Serialization example
The following example serializes a dog and its owner:
Dog fido = new Dog("Fido");
fido.Owner = new Person("Pete");
using (BlueprintContext context = new BlueprintContext())
{
context.Serialize("fido.xml", fido);
}
Output: (fido.xml)
<?xml version="1.0" encoding="utf-8"?>
<Blueprint bp:type="Samples.Dog, Samples" xmlns:bp="http://const.nl/blueprints">
<Name>Fido</Name>
<Owner>
<Name>Pete</Name>
</Owner>
</Blueprint>
The following example serializes the dog and its owner in separate files:
Dog fido = new Dog("Fido");
fido.Owner = new Person("Pete");
using (BlueprintContext context = new BlueprintContext())
{
// Register the reference to the owner to allow links to it
context.Register(fido.Owner);
// Serialize Pete in a separate file
context.Serialize("pete.xml", fido.Owner);
// Serialize Fido, automatically links to pete.xml
context.Serialize("fido.xml", fido);
}
Output:(pete.xml)
<?xml version="1.0" encoding="utf-8"?>
<Blueprint id="65f82092-217c-4c68-bd79-1d99e47d9fe4" bp:type="Samples.Person, Samples, Version=1.0.0.0" xmlns:bp="http://const.nl/blueprints">
<Name>Pete</Name>
</Blueprint>
(fido.xml)
<?xml version="1.0" encoding="utf-8"?>
<Blueprint bp:type="Samples.Dog, Samples, Version=1.0.0.0" xmlns:bp="http://const.nl/blueprints">
<Name>Fido</Name>
<Owner bp:link="file:///C:/Blueprints/Samples/bin/Debug/pete.xml#65f82092-217c-4c68-bd79-1d99e47d9fe4" />
</Blueprint>
Deserialization Example
The following example uses the files from the second serialization example, and deserializes a dog and its owner:
using (BlueprintContext context = new BlueprintContext())
{
Dog fido = context.Deserialize<Dog>("fido.xml");
Person pete = context.Deserialize<Person>("pete.xml");
Debug.Assert(fido.Owner == pete);
}