Chart for .NET / User's Guide / Serialization / Serialization Filters

Serialization Filters

Serialization filters allow you to control the object serialization by skipping objects that do not have to be serialized. Nevron Chart for .NET currently supports two built-in serialization filters, which can be extended or combined with custom serialization filters:

Serialization Filter Description Filtered Objects
NAppearanceSerializationFilter Serializes all appearance settings of the control and skips data. NDataSeries and NLegendItemCollection
NDataSerializationFilter Serializes all data and skips all properties related to the appearance of the control NFillStyle,NStrokeStyle, NFrameStyle, NShadowStyle.
 Using Serialization Filters

Now lets look at a simple code snippet showing how to preserve the appearance settings and discard the data of the chart when you serialize the control:

C#
Copy Code
NControlSerializer serializer = chartControl.Serializer;
NChart chart = chartControl.Charts[0];

// save the chart to file
MemoryStream memoryStream = new MemoryStream();
serializer.SaveToFile(chart, "c:\\temp\\chart.bin", PersistencyFormat.CustomBinary, new NDataSerializationFilter());

// load the chart from file
NChart chart2 = (NChart)serializer.LoadFromFile(typeof(NChart), "c:\\temp\\chart.bin", PersistencyFormat.CustomBinary, new NDataSerializationFilter());
Visual Basic
Copy Code
Dim serializer As NControlSerializer = chartControl.Serializer
Dim chart As NChart = chartControl.Charts(0)

' save the chart to file
serializer.SaveToFile(chart, "c:\\temp\\chart.bin", PersistencyFormat.CustomBinary, New NDataSerializationFilter())

' load the chart from file
Dim chart2 As NChart = CType(serializer.LoadFromFile(GetType(NChart), "c:\\temp\\chart.bin", PersistencyFormat.CustomBinary, New NDataSerializationFilter()), NChart)
 Extending Serialization Filters

Both the NDataSerializationFilter and NAppearanceSerializationFilter derive from the NSerializationFilter that implements the INSerializationFilter interface. The NSerializationFilter class has several properties controlling which objects are to be serialized. The following code adds the NMarkerStyle type to the non serialized objects:

C#
Copy Code
ArrayList types = new ArrayList();
types.Add(typeof(NFillStyle));

NDataSerializationFilter filter = new NDataSerializationFilter();
filter.SetNonSerializedTypes(types);
Visual Basic
Copy Code
Dim types As ArrayList = New ArrayList
types.Add(GetType(NFillStyle))

Dim filter As New NDataSerializationFilter
filter.SetNonSerializedTypes(types)
Note that you may also use regular expressions strings like "*.FillStyle".
 Related Examples
Windows Forms: Serialization\Chart Objects Windows Forms: Serialization\Control State
See Also