Home
PineCone is just something I have lifted out of one of my other open source projects SisoDb http://sisodb.com.
It 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 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
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
var pineConizer = new PineConizer();
var structures = pineConizer.CreateStructuresFor(items);
Build structures a more manual way
var schema = pineConizer.Schemas.GetSchema(typeof(X));
//OR
var schema = pineConizer.Schemas.GetSchema<X>();
var structures = pineConizer.Builder.CreateStructures(items, schema);
Access
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; }
}
Serializer
Implement ISerialzer
public interface ISerializer
{
dynamic Serialize<T>(T item);
}
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/