bovender framework
C# framework that implements MVVM and more
Bovender.UserSettings.UserSettingsBase Class Reference

Base class for persistent settings; a replacement for the UserSettings.UserSettingsBase system which has a couple of quirks and whose files are hard to find, read, and write by humans. More...

Inheritance diagram for Bovender.UserSettings.UserSettingsBase:
Bovender.UnitTests.UserSettings.UserSettings

Public Member Functions

void Save ()
 Saves the user settings to a file. More...
 
virtual string GetSettingsFilePath ()
 Gets the complete path and file name for the user settings file. More...
 

Static Public Member Functions

static void LoadDefaults ()
 Creates a new settings object without loading the saved settings from file and without saving the current settings from file. More...
 

Protected Member Functions

virtual SerializerBuilder ConstructSerializerBuilder ()
 Builds a YamlDotNet serializer builder. More...
 
virtual void WriteYamlHeader (StreamWriter streamWriter)
 Writes a header to the YAML file before all other data. More...
 

Static Protected Member Functions

static T FromFileOrDefault< T > (string yamlFile, DeserializerBuilder deserializerBuilder)
 Loads options from a file, or creates a default instance if the I/O operation failed. More...
 
static T FromFileOrDefault< T > (string yamlFile)
 Loads options from a file using default YAML deserialization options (ignoring unmatched properties), or creates a default instance if the I/O operation failed. More...
 

Properties

static UserSettingsBase Default [get, set]
 Gets the singleton instance of the user settings. More...
 
string User [get, set]
 
string Email [get, set]
 
bool CcUserOnExceptionReport [get, set]
 
string DownloadFolder [get, set]
 
bool WasFromFile [get, protected set]
 Is true if the options store was initially loaded from a YAML file. More...
 
Exception Exception [get, protected set]
 Gets the last IOException, if any occurred. More...
 

Detailed Description

Base class for persistent settings; a replacement for the UserSettings.UserSettingsBase system which has a couple of quirks and whose files are hard to find, read, and write by humans.

To make use of this options system, derive your own class from OptionsBase and add properties to it. These will be automatically saved to and loaded from a YAML file.

Definition at line 39 of file UserSettingsBase.cs.

Member Function Documentation

virtual SerializerBuilder Bovender.UserSettings.UserSettingsBase.ConstructSerializerBuilder ( )
inlineprotectedvirtual

Builds a YamlDotNet serializer builder.

This method may be overridden to provide a serializer builder with RoundTrip enabled, for example.

Returns
SerializerBuilder instance.

A custom SerializerBuilder with .EnsureRoundTrip() is needed if the derived settings class has polymorphic properties, which cannot be deserialized unless the additional info provided by .EnsureRoundTrip() is included in the YAML file. This is not enabled by default because it adds a lot of technical information to the YAML file, which may be perceived as noise.

Definition at line 292 of file UserSettingsBase.cs.

static T Bovender.UserSettings.UserSettingsBase.FromFileOrDefault< T > ( string  yamlFile,
DeserializerBuilder  deserializerBuilder 
)
inlinestaticprotected

Loads options from a file, or creates a default instance if the I/O operation failed.

This is a protected method. Implementations of UserSettingsBase must provide simple-access methods defined in IUserSettings to make life easier for the outside world.

Parameters
yamlFilePath to a YAML file that holds the options.
deserializerBuilderYamlDotNet DeserializerBuilder object that is used to build the YAML deserializer.
Template Parameters
TType of the OptionsStore derivative to load.
Returns
OptionsStore object, either with values loaded from file or with default values.
Type Constraints
T :UserSettingsBase 
T :new() 

Definition at line 80 of file UserSettingsBase.cs.

static T Bovender.UserSettings.UserSettingsBase.FromFileOrDefault< T > ( string  yamlFile)
inlinestaticprotected

Loads options from a file using default YAML deserialization options (ignoring unmatched properties), or creates a default instance if the I/O operation failed.

This is a protected method. Implementations of UserSettingsBase must provide simple-access methods defined in IUserSettings to make life easier for the outside world.

Parameters
yamlFilePath to a YAML file that holds the options.
Template Parameters
TType of the OptionsStore derivative to load.
Returns
OptionsStore object, either with values loaded from file or with default values.
Type Constraints
T :UserSettingsBase 
T :new() 

Definition at line 133 of file UserSettingsBase.cs.

virtual string Bovender.UserSettings.UserSettingsBase.GetSettingsFilePath ( )
inlinevirtual

Gets the complete path and file name for the user settings file.

Applications using this framework should override this.

Definition at line 303 of file UserSettingsBase.cs.

static void Bovender.UserSettings.UserSettingsBase.LoadDefaults ( )
inlinestatic

Creates a new settings object without loading the saved settings from file and without saving the current settings from file.

Derived classes should implement their own static variant of this method (which cannot be marked virtual because it is static), in order to generate an instance of the derived class, rather than an instance of UserSettingsBase.

Definition at line 221 of file UserSettingsBase.cs.

void Bovender.UserSettings.UserSettingsBase.Save ( )
inline

Saves the user settings to a file.

Definition at line 256 of file UserSettingsBase.cs.

virtual void Bovender.UserSettings.UserSettingsBase.WriteYamlHeader ( StreamWriter  streamWriter)
inlineprotectedvirtual

Writes a header to the YAML file before all other data.

To write comments, prefix lines with "#".

Definition at line 315 of file UserSettingsBase.cs.

Property Documentation

UserSettingsBase Bovender.UserSettings.UserSettingsBase.Default
staticgetset

Gets the singleton instance of the user settings.

Applications that use this framework may want to replace the default singleton with an instance of their own (UserSettingsBase.Default = myInstance), in order to avoid having two separate settings files, one for the Bovender framework and one for the application itself.

Definition at line 51 of file UserSettingsBase.cs.

Exception Bovender.UserSettings.UserSettingsBase.Exception
getprotected set

Gets the last IOException, if any occurred.

Definition at line 241 of file UserSettingsBase.cs.

bool Bovender.UserSettings.UserSettingsBase.WasFromFile
getprotected set

Is true if the options store was initially loaded from a YAML file.

Definition at line 235 of file UserSettingsBase.cs.


The documentation for this class was generated from the following file: