Building a Windows 8 Metro App, Part 3: Listing 1

SettingsStorage.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
namespace VSMWinRTDemo.Storage
{
    public class SettingsStorage
    {
        public static T GetLocalSetting<T>string key)
        {
            T result = default(T);
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey(key))
            {
                result = (T)ApplicationData.Current.LocalSettings.Values[key];
            }
            return result;
        }
        public static void SetLocalSetting(string key, Object value)
        {
            ApplicationData.Current.LocalSettings.Values[key] = value
	}
    }
}

About the Author

Eric Vogel is a Senior Software Developer for Red Cedar Solutions Group in Okemos, Michigan. He is the president of the Greater Lansing User Group for .NET. Eric enjoys learning about software architecture and craftsmanship, and is always looking for ways to create more robust and testable applications. Contact him at [email protected].

comments powered by Disqus

Featured

Subscribe on YouTube