This is a mirror of official site: http://jasper-net.blogspot.com/

Generic Object Storage Helper for WinRT

| Sunday, October 23, 2011
Project Description
ObjectStorageHelper<T> is a Generic class that simplifies storage of data in WinRT applications.

Overview
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.

Restrictions
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

[TestMethod]
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
  objectStorageHelper.SaveASync(myPoco);
}

Read more: Codeplex
QR: https://chart.googleapis.com/chart?chs=80x80&cht=qr&choe=UTF-8&chl=http://winrtstoragehelper.codeplex.com/

Posted via email from Jasper-net

0 comments: