在他的回答For which scenarios is protobuf-net not appropriate?馬克提到:如何使用protobuf-net序列化/反序列化鋸齒狀/嵌套數組?
交錯數組/嵌套,沒有中間類型的名單都不行 - 你可以通過在中間
我引入一箇中間類型墊片這希望這表明有一種方法可以在不改變我的底層代碼的情況下做到,也許使用代理? 有沒有人發現一個好的方法來序列化/反序列化嵌套/鋸齒狀陣列
在他的回答For which scenarios is protobuf-net not appropriate?馬克提到:如何使用protobuf-net序列化/反序列化鋸齒狀/嵌套數組?
交錯數組/嵌套,沒有中間類型的名單都不行 - 你可以通過在中間
我引入一箇中間類型墊片這希望這表明有一種方法可以在不改變我的底層代碼的情況下做到,也許使用代理? 有沒有人發現一個好的方法來序列化/反序列化嵌套/鋸齒狀陣列
在當前時間,它會要求(如消息所示)改變你的模型。然而,原則上這是圖書館完全可以在自己的想象中完成的事情 - 這只是我還沒有編寫/測試過的代碼。所以這取決於你需要多久...我可以看看它,但我不能保證任何特定的時間表。
解決方案可能是序列化中間類型,並使用getter/setter將其從代碼的其餘部分隱藏。 實施例:
List<double[]> _nestedArray ; // The nested array I would like to serialize.
[ProtoMember(1)]
private List<ProtobufArray<double>> _nestedArrayForProtoBuf // Never used elsewhere
{
get
{
if (_nestedArray == null) // (_nestedArray == null || _nestedArray.Count == 0) if the default constructor instanciate it
return null;
return _nestedArray.Select(p => new ProtobufArray<double>(p)).ToList();
}
set
{
_nestedArray = value.Select(p => p.MyArray).ToList();
}
}
[ProtoContract]
public class ProtobufArray<T> // The intermediate type
{
[ProtoMember(1)]
public T[] MyArray;
public ProtobufArray()
{ }
public ProtobufArray(T[] array)
{
MyArray = array;
}
}
的可能重複的[?使用protobuf網,如何(DE)序列化多維陣列(http://stackoverflow.com/questions/4090173/using-protobuf-net- how-to-deserialize-a-multi-dimensional-array) – 2015-08-09 01:32:52