PineCone (https://github.com/danielwertheim/PineCone) is a new open source project I just created. As of now it’s just a component that is a result of things I have used in one of my other open source projects SisoDb http://sisodb.com. I’m intending to use PineCone in a third project coming soon.
PineCone lets you take a C# class and then builds a schema for this class. This schema contains cached members that via IL Emit extracts all simple values from the object graph. All values are turned into a StructureIndex, which is contained by a Structure. Each StructureIndex holds a Guid pointing back to the structure so that you easily can navigate to the structure again.
You can also provide an implementation of ISerializer https://github.com/danielwertheim/PineCone/blob/master/Solution/Source/PineCone/Serialization/ISerializer.cs on the StructureBuilder, which then will be called for each item being converted to a structure. The result of the serializer will be put in the IStructure.Data property.
Model
Example of model with nested complex and enumerable of complex items.
public class X
{
public Guid StructureId { get; set; }
[Unique(UniqueModes.PerType)]
public int X1 { get; set; }
public int[] X2 { get; set; }
public Y X3 { get; set; }
public IList<Y> X4 { get; set; }
}
public class Y
{
public string Y1 { get; set; }
public int Y2 { get; set; }
public IList<Z> Y3 { get; set; }
}
public class Z
{
public DateTime Z1 { get; set; }
public decimal Z2 { get; set; }
}
Build structures
The process is simple. Get a schema from the Schemas (keep the Schemas-collection alive to keep schemas cached). Use the schema to build structures using the builder.
var pineConizer = new PineConizer();
var schema = pineConizer.Schemas.GetSchema(typeof(X));
var structures = pineConizer.Builder.CreateStructures(items, schema);
Access structures and indexes
As of now you have a structure with indexes.
var p = structures.SelectMany(s => s.Indexes).Where(i => i.Path.StartsWith("X3") || i.Value is string);
IStructure
public interface IStructure
{
Guid Id { get; }
string Name { get; }
dynamic Data { get; set; }
ISet<IStructureIndex> Indexes { get; }
ISet<IStructureIndex> Uniques { get; }
}
IStructureIndex
public interface IStructureIndex : IEquatable<IStructureIndex>
{
Guid StructureId { get; }
string Path { get; }
object Value { get; }
bool IsUnique { get; }
StructureIndexType IndexType { get; }
}
Serializer
Implement ISerialzer
public interface ISerializer
{
dynamic Serialize<T>(T item);
}
To get the serializer into play, you need to assign it to the builder.
pineConizer.Builder.Serializer = mySerializer;
After this your structures will have their Data prop filled with the serialized content. For JSON I highly recommend https://github.com/ServiceStack/ServiceStack.Text as it is the most performant I know: http://daniel.wertheim.se/2011/02/07/json-net-vs-servicestack/
The end. Will get back with examples of use-cases.
//Daniel
