02-07-2019 07:28 AM
Hello,
I have my C# class with public properties and I do serialization of the instance of this class to XML file. And I would like to serialize also ChartCollection public property. Is it actually serializable? Or how to do it the best and easiest way?
Thank you for support.
Solved! Go to Solution.
02-08-2019 10:08 AM
The chart collection types do not support serialization directly, so you will need to use some sort of helper to perform the serialization. I am not directly familiar with XML serialization, but attached is my attempt at creating a serialization helper for chart collections. It should support any of the Measurement Studio chart collection types (although you may want to optimize it for your specific use case).
Here is the test code I used:
var chart = new ChartCollection<double> { 1, 2, 3 }; var helper = new SerializableDataCollection { Collection = chart }; var serializer = new XmlSerializer( helper.GetType( ) ); using( var writer = new StringWriter( ) ) { serializer.Serialize( writer, helper ); using( var reader = new StringReader( writer.ToString( ) ) ) { var result = (SerializableDataCollection)serializer.Deserialize( reader ); } }
02-14-2019 03:01 AM
Thank you very much for help and good example. It's the shame that ChartCollection is not serializable. I did it a little bit different way. I created my helper collection (serializable class) with lists and use it for serialization / deserialization of chart collections data.
Anyway, problem solved.