[Serializable]
[ProtoContract]
public class DataWrapper
{
[ProtoMember(1)]
public double[] Data = new double[] { 1, 2, 3, 4 };
}
class Program
{
static void Main(string[] args)
{
Dictionary<int, DataWrapper> serialized = new Dictionary<int, DataWrapper>();
Dictionary<int, DataWrapper> deserialized;// = new Dictionary<int, OHLC>();
for (int i = 0; i < 10; i++)
{
serialized.Add(i, new DataWrapper());
}
using (FileStream ms = new FileStream("dictionary", FileMode.Create, FileAccess.Write))
{
Serializer.Serialize<Dictionary<int, DataWrapper>>(ms, serialized);
}
using (FileStream ms = new FileStream("dictionary", FileMode.Open, FileAccess.Read))
{
deserialized = Serializer.Deserialize<Dictionary<int, DataWrapper>>(ms);
}
Console.WriteLine("serialized {0} and deserialized {1}", serialized[0].Data.Length, deserialized[0].Data.Length);
}
}
我期望反序列化一个长度为 4 的数组,而我收到一个长度为 8 的数组。这是一个错误,还是我在这里做错了?
请注意,代码是没有意义的。这只是试图解释我在真实场景中面临的问题