Home > C#, CodePlex, WinRT > An helper class to store data in WinRT applications

An helper class to store data in WinRT applications

12/12/2012

Generic Object Storage Helper for WinRT is an open source library, available on CodePlex, that greatly simplifies storage of data in WinRT apps. It uses XML serialization, so it can be used with every object that can be serialized in this format.

The following are usage examples you can find on the Home Page of the project:

public async Task SaveObject()
{
  //Instantiate an object that we want to save
  var myPoco = new Poco() { IntProp = 1, StringProp = "one" };
  //new up ObjectStorageHelper specifying that we want to interact with
  //the Local storage folder
  var objectStorageHelper = new ObjectStorageHelper<Poco>(StorageType.Local);
  //Save the object (via XML Serialization) to the specified folder, asynchronously
  await objectStorageHelper.SaveAsync(myPoco);
}

public async void LoadObject()
{
  //new up ObjectStorageHelper specifying that we want to interact with
  //the Local storage folder
  var objectStorageHelper = new ObjectStorageHelper<Poco>(StorageType.Local);
  //Get the object from the storage folder
  Poco myPoco = await objectStorageHelper.LoadAsync();
}

In these methods, we use StorageType.Local, to store data in the Local application folder. Other values allow us to use the Roaming or the Temporary folder.

The library is available via NuGet too.

Categories: C#, CodePlex, WinRT
%d bloggers like this: