XML serialization and necessary public properties

in my Silverlight 4 application, I save my object using the DataContractSerializer XML-Serialization - which is pretty simple:

public byte[] SerializeModel(ServiceModel model)
{
    System.Runtime.Serialization.DataContractSerializer serializer = new System.Runtime.Serialization.DataContractSerializer(typeof(ServiceModel));
    System.IO.MemoryStream ms = new System.IO.MemoryStream();

    serializer.WriteObject(ms, model);

    byte[] bytes = ms.ToArray();
    ms.Close();

    return bytes;
}

... and easily download them via:

public ServiceModel DeserializeModel(string stream)
{
    System.Runtime.Serialization.DataContractSerializer serializer = new System.Runtime.Serialization.DataContractSerializer(typeof(ServiceModel));
    System.Xml.XmlReader reader = System.Xml.XmlReader.Create(new System.IO.StringReader(stream));

    object result = serializer.ReadObject(reader);

    return (ServiceModel)result;
}

(Error handling error)

The problem for me is that I need to make the data to save (or better: to load) public properties using getter and setter. This results in loss of data integrity control. That is, I have a set of objects, and I want to control which objects need to be added or deleted. I will need to subclass or reimplement the collection, change the add and remove methods, and any other method that I will need to control. But, making it private, I cannot use the DataContractSerializer.

, , ?

,

+3
1

, , POCOs ( /), , , , , /.

, , "" , POCO, , , / . , -, . , -, - .

, , , , , .

$0,02

+2

All Articles