在他的回答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