Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

ChartCollection serialization

Solved!
Go to solution

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.

 

0 Kudos
Message 1 of 3
(2,505 Views)
Solution
Accepted by topic author Zelva

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 );
    }
}
~ Paul H
0 Kudos
Message 2 of 3
(2,482 Views)
Solution
Accepted by topic author Zelva

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.

0 Kudos
Message 3 of 3
(2,468 Views)