Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

Abstract class: RT.Util.SettingsBase

Summary

Provides a base class for settings classes, implementing certain common usage patterns. See remarks for detailed usage instructions.

Remarks

Derive a class from this one and add the fields you wish to persist. Mark those you don't want stored with the ClassifyIgnoreAttribute. You must mark the derived class with SettingsAttribute.

Once the above is done, the settings can be saved by calling SettingsBase.Save(string, SettingsSerializer?, SettingsOnFailure)/SettingsBase.SaveQuiet(string, SettingsSerializer?), depending on intent. To load, call SettingsUtil.LoadSettings<TSettings>(out TSettings, string, SettingsSerializer?), making sure that the generic type is the type of your descendant class. For example:

static class Program
{
    public static MySettings Settings;

    static void Main(string[] args)
    {
        SettingsUtil.LoadSettings(out Settings);
        DoWork();
        Settings.Save();
    }
}

[Settings("MyApplicationName", SettingsKind.UserSpecific)]
class MySettings : SettingsBase
{
    public string SomeSetting = "initial/default value";
}

SettingsThreadedBase implements an extra method to enable settings to be queued for a save on a separate thread, to reduce the performance impact of less important saves.

Instance methods

void
Delete(string filename = null, SettingsOnFailure onFailure = SettingsOnFailure.Throw)
  • Virtual
Deletes the settings file.
void
Save(string filename = null, SettingsSerializer? serializer = null, SettingsOnFailure onFailure = SettingsOnFailure.Throw)
  • Virtual

Saves the settings.

This method is fully compatible with SettingsThreadedBase.SaveThreaded(string, SettingsSerializer?), and will cancel any pending earlier (older) saves.

void
SaveLoud(string filename = null, SettingsSerializer? serializer = null)
  • Virtual

Saves the settings. Intended to be used whenever the settings are important enough to bug the user if this fails.

This method is fully compatible with SettingsThreadedBase.SaveThreaded(string, SettingsSerializer?), and will cancel any pending earlier (older) saves.

void
SaveQuiet(string filename = null, SettingsSerializer? serializer = null)
  • Virtual

Saves the settings. Intended to be used whenever the settings are not important enough to bug the user if this fails.

This method is fully compatible with SettingsThreadedBase.SaveThreaded(string, SettingsSerializer?), and will cancel any pending earlier (older) saves.

Instance properties

SettingsAttribute Gets the SettingsAttribute instance specified on this settings class, or null if none are specified.