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...
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... | |
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.
|
inlineprotectedvirtual |
Builds a YamlDotNet serializer builder.
This method may be overridden to provide a serializer builder with RoundTrip enabled, for example.
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.
|
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.
| yamlFile | Path to a YAML file that holds the options. |
| deserializerBuilder | YamlDotNet DeserializerBuilder object that is used to build the YAML deserializer. |
| T | Type of the OptionsStore derivative to load. |
| T | : | UserSettingsBase | |
| T | : | new() |
Definition at line 80 of file UserSettingsBase.cs.
|
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.
| yamlFile | Path to a YAML file that holds the options. |
| T | Type of the OptionsStore derivative to load. |
| T | : | UserSettingsBase | |
| T | : | new() |
Definition at line 133 of file UserSettingsBase.cs.
|
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.
|
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.
|
inline |
Saves the user settings to a file.
Definition at line 256 of file UserSettingsBase.cs.
|
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.
|
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.
|
getprotected set |
Gets the last IOException, if any occurred.
Definition at line 241 of file UserSettingsBase.cs.
|
getprotected set |
Is true if the options store was initially loaded from a YAML file.
Definition at line 235 of file UserSettingsBase.cs.