Hi,
I need to serialize some data to string. The string is then stored in DB in a special column SerializeData.
I have created special classes that are used for serialization.
[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;
}
Now I want to have versioning support. What happens if I change SerializableContingentOrder
class. I want to be able to add new fields in the future.
Do I have to switch to DataContract serialization? Please give me short snippet?