Импульсивный IBsonSerializer сработал :) Сделал быстрый макет, и он сработал довольно хорошо: я получил еще одно предложение от того, кто сказал, что List<T>
подойдет, попробую это позже на этой неделе.И опубликовать результаты здесь.
/* 3131 */
{
"_id" : ObjectId("4e4d58df77d2cf00691aaef2"),
"ItemId" : 28432,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 23448,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 23447,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 23427,
"Quantity" : 2,
"Reagents" : []
}]
}, {
"ItemId" : 23445,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 23424,
"Quantity" : 2,
"Reagents" : []
}]
}]
}, {
"ItemId" : 23572,
"Quantity" : 8,
"Reagents" : []
}, {
"ItemId" : 28431,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 23571,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 21885,
"Quantity" : 1,
"Reagents" : []
}, {
"ItemId" : 21884,
"Quantity" : 1,
"Reagents" : []
}, {
"ItemId" : 22451,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 21885,
"Quantity" : 1,
"Reagents" : []
}]
}, {
"ItemId" : 22452,
"Quantity" : 1,
"Reagents" : []
}, {
"ItemId" : 22457,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 21884,
"Quantity" : 1,
"Reagents" : []
}]
}]
}, {
"ItemId" : 22456,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 21885,
"Quantity" : 1,
"Reagents" : []
}]
}, {
"ItemId" : 23573,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 23446,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 23425,
"Quantity" : 2,
"Reagents" : []
}]
}]
}, {
"ItemId" : 23448,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 23447,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 23427,
"Quantity" : 2,
"Reagents" : []
}]
}, {
"ItemId" : 23445,
"Quantity" : 0,
"Reagents" : [{
"ItemId" : 23424,
"Quantity" : 2,
"Reagents" : []
}]
}]
}]
}]
}
Сериализация подразумевает:
public void Serialize(MongoDB.Bson.IO.BsonWriter bsonWriter, Type nominalType, MongoDB.Bson.Serialization.IBsonSerializationOptions options)
{
if (nominalType != typeof(IReagent) && nominalType != typeof(Reagent) && nominalType != typeof(Craft))
{
throw new ArgumentException("Cannot serialize anything but self");
}
bsonWriter.WriteStartDocument();
bsonWriter.WriteInt32("ItemId", this.ItemId);
bsonWriter.WriteInt32("Quantity", this.Quantity);
if (this.Reagents != null)
{
bsonWriter.WriteName("Reagents");
bsonWriter.WriteStartArray();
foreach (var r in this.Reagents)
{
BsonSerializer.Serialize(bsonWriter, r.GetType(), r, options);
}
bsonWriter.WriteEndArray();
}
bsonWriter.WriteEndDocument();
}