This section briefly touches on the topic of abstracting the IsolatedStorageSettings
class. By providing a custom API for application settings, it decouples your code from the .NET-specific IsolatedStorageSettings
class and allows you to change the way settings are stored, thereby increasing the portability of your code.
The IsolatedStorageSettings
class uses a DataContractSerializer
that serializes objects using XML, which is significantly slower than, for example, a binary serializer.
In the Calcium project there exists an ISettingsService
that includes methods to retrieve items from persistent storage. The Calcium settings API allows you to retrieve a value from isolated storage while supplying a default value, which is returned if no value exists, as shown in the following example:
var settingsService = Dependency.Resolve<ISettingsService>();
int exampleSetting = settingsService.GetSetting("Example Setting Key", 5);
The GetSetting
method uses generics to return an object of the correct type, matching the default value’s type.
To set a value, the SetSetting
method is called like so:
settingsService.SetSetting("Example Setting Key", 2);
We do not delve deeper into the code in this chapter, but if you are interested in this topic, the source code is open source and freely available at http://calciumsdk.com.
18.119.116.43