Generic Storage Manager

All of my apps make use of a common class for data storage management. Its simple and works for my needs, even providing a way to create a default context if one does not already exist.

Obviously any type you want to use with this must be decorated with the DataContractAttribute.

class StorageManager<T> where T : class 
{
	private readonly string _filename;
	private readonly Func<T> _defCtxFunc;
	
	public StorageManager(string filename, Func<T> defaultContextCreation)
	{
		_filename = filename;
		_defCtxFunc = defaultContextCreation;
	}
	
	public async Task<T> Load(Func<T> defaultContextCreation)
	{
		object existingData = null;

		try
		{
			var serializer = new DataContractSerializer(typeof (T));
			using (
				var stream =
					await
						ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(_filename))

			{
				existingData = serializer.ReadObject(stream);
				stream.Flush();
			}
		}
		catch (Exception e)
		{
			Debug.WriteLine("StorageManager.Load({1}) failed with exception :: {0}", _filename, e);
		}

		return (existingData ?? defaultContextCreation.Invoke()) as T;
	}

	public async Task<bool> Save(T data)
	{
		try
		{
			var serializer = new DataContractSerializer(typeof (T));
			using (
				var stream =
					await
						ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(_filename,
							CreationCollisionOption.ReplaceExisting))
			{
				serializer.WriteObject(stream, data);
				stream.Flush();                    
			}

			Debug.WriteLine("Save [{0}] to [{1}] success", _filename, ApplicationData.Current.LocalFolder.Path);
			return true;
		}
		catch(Exception e)
		{
			Debug.WriteLine("Save [{0}] failed with exception :: {1}", _filename, e);
			return false;
		}
	}
}