Syncfusion.Runtime.Serialization Namespace : AppStateSerializer Class

AppStateSerializer Class

Provides a mechanism for coordinating the serialization behavior of multiple components.
Object Model
AppStateSerializer ClassCustomSerializationBinder Class
Public NotInheritable Class AppStateSerializer 
Dim instance As AppStateSerializer
public sealed class AppStateSerializer 

The AppStateSerializer class is a serialization utility that allows multiple components in an application to access a common disk I/O medium for state persistence. Using the same storage medium for persisting the state information across components, without overtly tying them together, helps avoid the file clutter that is bound to occur by components using distinct files. Though primarily developed for use by Syncfusion products, the AppStateSerializer is generic enough to be availed of by other components as well.

The AppStateSerializer supports serializing into the system's Isolated Storage, Windows Registry, an XML file, a binary file or to an externally provided Stream. Take a look at the SerializeMode enumeration for more information on these different supported modes.

To use the services of this class, you can create a new instance or use the global Singleton instance. These two usage patterns are explained below:

1) Using the Singleton: The AppStateSerializer class provides you a singleton instance (through the GetSingleton) using which you can persist all your app. info into a single medium. This singleton, by default, is configured to persist in the Isolated Storage (with the scope IsolatedStorageScope.Assembly|IsolatedStorageScope.Domain|IsolatedStorageScope.User). This usage pattern is akin to creating an instance of this class and using the same instance to persist all your app information. But, note that this Singleton is also used by the Controls and Components in Essential Tools to persist their information. The default Storage medium of this Singleton instance can also be customized using the static InitializeSingleton(SerializeMode,Object) method. In short, use the Singleton whenever you want all your persistence information to be stored in a single medium (along with the persistence information of the Controls and Components in Essential Tools).

2) Using an instance: As an alternative you could create a custom instance of this class, configuring it to use one of the above storage mediums and persist one or more information into it. You can use this in tandem with the above Singleton instance if you wish. Make sure to call PersistNow method when you are done writing into the serializer.

In both the above cases use the method's SerializeObject(String,Object) and DeserializeObject to persist or depersist from the storage medium set for that instance.

Note that the AppStateSerializer class uses "Simple" type names (not strongly typed) to serialize types. This is necessary to enable usage of persisted information across different but compatible versions of an assembly. This will however cause the deserialization process to convert the serialized data to the type from the latest version of the assembly installed in the GAC, instead of the version that your app is linking to. You can overcome this by using the SetBindingInfo method.


Serializing using an instance: // To Save AppStateSerializer serializer = new AppStateSerializer(SerializeMode.XMLFile, "myfile"); serializer.SerializeObject("MyLabel", mydata); serializer.PersistNow(); // To Load AppStateSerializer serializer = new AppStateSerializer(SerializeMode.XMLFile, "myfile"); object loadedObj = serializer.DeserializeObject("MyLabel"); if(loadedObj != null && loadedObj is MyData) { MyData myData = (MyData)loadedObj; } ' To Save Dim serializer As New AppStateSerializer(SerializeMode.XMLFile, "myfile") serializer.SerializeObject("MyLabel", mydata) serializer.PersistNow() ' To Load Dim serializer As New AppStateSerializer(SerializeMode.XMLFile, "myfile") Dim loadedObj As Object = serializer.DeserializeObject("MyLabel") If TypeOf loadedObj Is MyData Then Dim myData As MyData = CType(loadedObj, MyData) End If

Serializing using Singleton: // To Save AppStateSerializer.GetSingleton().SerializeObject("MyLabel", mydata, true); // To Load object loadedObj = AppStateSerializer.GetSingleton().DeserializeObject("MyLabel"); ' To Save AppStateSerializer.GetSingleton().SerializeObject("MyLabel", mydata, true) ' To Load Dim loadedObj As Object = AppStateSerializer.GetSingleton().DeserializeObject("MyLabel")

Inheritance Hierarchy



Syncfusion.Shared.Base: 17.4460.0.46

See Also