Sunday, October 23, 2011

Generic Object Storage Helper for WinRT

Project Description
ObjectStorageHelper<T> is a Generic class that simplifies storage of data in WinRT applications.

While exploring WinRT I came up with this, ObjectStorageHelper<T>, a Generic class that wraps (and greatly simplifies) use of the RoamingFolder, TemporaryFolder & LocalFolder storage folders within the ApplicationData class.

With ObjectStorageHelper<T> saving and loading an object to/from disk is now just a simple method call.

Under the covers ObjectStorageHelper<T> uses XML Serialization hence T needs to be an object that can be serialized as XML. There is a useful thread on Stack Overflow Using .Net what limitations (if any) are there in using the XmlSerializer? that talks about those restrictions better than I ever could.

Saving an object
Using ObjectStorageHelper<T> saving an object only takes two lines of code

public void 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

Read more: Codeplex

Posted via email from Jasper-Net