Tôi cần serialize một số dữ liệu vào chuỗi. Chuỗi này sau đó được lưu trữ trong DB trong một cột đặc biệt SerializeData.Nối tiếp và phiên bản
Tôi đã tạo các lớp đặc biệt được sử dụng để tuần tự hóa.
[Serializable]
public class SerializableContingentOrder
{
public Guid SomeGuidData { get; set; }
public decimal SomeDecimalData { get; set; }
public MyEnumerationType1 EnumData1 { get; set; }
}
serialization:
protected override string Serialize()
{
SerializableContingentOrder sco = new SerializableContingentOrder(this);
MemoryStream ms = new MemoryStream();
SoapFormatter sf = new SoapFormatter();
sf.Serialize(ms, sco);
string data = Convert.ToBase64String(ms.ToArray());
ms.Close();
return data;
}
Deserialization:
protected override bool Deserialize(string data)
{
MemoryStream ms = new MemoryStream(Convert.FromBase64String(data).ToArray());
SoapFormatter sf = new SoapFormatter();
SerializableContingentOrder sco = sf.Deserialize(ms) as SerializableContingentOrder;
ms.Close();
return true;
}
Bây giờ tôi muốn có versioning hỗ trợ. Điều gì xảy ra nếu tôi thay đổi lớp SerializableContingentOrder
. Tôi muốn có thể thêm các trường mới trong tương lai.
Tôi có phải chuyển sang nối tiếp DataContract không? Xin vui lòng cho tôi đoạn mã ngắn?
Xem MSDN; 'SoapFormatter' là lỗi thời chính thức: http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.soap.soapformatter.aspx –
Tôi cần phải đặt câu hỏi tương tự nhưng một chút mở rộng của nó. Dữ liệu sẽ thay đổi chắc chắn, chúng ta có thể làm cho cấu trúc dữ liệu tự xử lý thay đổi tiếp theo không? –