Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/DevToys-app/DevToys/llms.txt

Use this file to discover all available pages before exploring further.

ISettingsProvider is the single interface through which DevToys extensions read and write persistent user preferences. The host injects it via MEF, and your tool interacts with it through strongly-typed SettingDefinition<T> keys — no raw string keys, no manual serialization. Settings are persisted across app restarts and, for portable installations, stored in a .ini file alongside the executable. Namespace: DevToys.Api

Injection

Import ISettingsProvider into your tool class using the standard MEF [Import] attribute:
[Import]
private ISettingsProvider _settingsProvider = null!;

Interface Declaration

public interface ISettingsProvider
{
    event EventHandler<SettingChangedEventArgs>? SettingChanged;

    T GetSetting<T>(SettingDefinition<T> settingDefinition);

    void SetSetting<T>(SettingDefinition<T> settingDefinition, T value);

    void ResetSetting<T>(SettingDefinition<T> settingDefinition);
}

Members

SettingChanged
event EventHandler<SettingChangedEventArgs>?
Raised whenever any setting in the application changes, including settings from other tools. Subscribe to this event to react to preference changes without polling.The SettingChangedEventArgs carries:
PropertyTypeDescription
SettingNamestringThe fully-qualified internal name of the setting that changed.
NewValueobject?The new value, boxed as object?. Cast to T before use.
GetSetting<T>(SettingDefinition<T> settingDefinition)
T
Returns the current persisted value of the setting, or settingDefinition.DefaultValue if it has never been set.
ParameterTypeDescription
settingDefinitionSettingDefinition<T>The definition that uniquely identifies the setting.
SetSetting<T>(SettingDefinition<T> settingDefinition, T value)
void
Persists value for the given setting. Fires SettingChanged after the write completes.
ParameterTypeDescription
settingDefinitionSettingDefinition<T>The definition that uniquely identifies the setting.
valueTThe new value to persist.
ResetSetting<T>(SettingDefinition<T> settingDefinition)
void
Deletes the persisted value and restores the setting to settingDefinition.DefaultValue. Also fires SettingChanged.
ParameterTypeDescription
settingDefinitionSettingDefinition<T>The definition to reset.

SettingDefinition<T>

A SettingDefinition<T> is a lightweight readonly struct that acts as the key for a setting. Declare it as a static readonly field so it is created once and reused across all accesses.

Constructors

// Simple — type must be natively serializable (bool, int, string, enum, etc.)
new SettingDefinition<T>(string name, T defaultValue)

// Advanced — supply custom serialize/deserialize callbacks for complex types
new SettingDefinition<T>(string name, T defaultValue,
    Func<T, string> serialize,
    Func<string, T> deserialize)

Naming Rules

Setting names must not contain =. In portable mode, settings are stored in a .ini file using the format setting_name=value, so an = in the name would corrupt the file. The constructor throws ArgumentException if the name contains one.
  • Use a reverse-DNS–style prefix (e.g., "MyCompany.MyTool.EncodingMode") to avoid name collisions with other extensions.
  • Names are limited to 255 characters including the assembly prefix that SettingDefinition adds automatically via stack-trace reflection.
  • The framework prefixes your name with the calling assembly name at construction time, so two extensions that both use "MyToggle" will not conflict.

Properties

PropertyTypeDescription
NamestringThe fully-qualified internal name (assembly prefix + your name).
DefaultValueTThe value returned when the setting has never been set.
SerializeFunc<T, string>?Optional custom serializer. null for primitive types.
DeserializeFunc<string, T>?Optional custom deserializer. null for primitive types.

SettingChangedEventArgs

public sealed class SettingChangedEventArgs : EventArgs
{
    public string SettingName { get; }
    public object? NewValue { get; }
}
SettingName is the fully-qualified internal name (same as SettingDefinition<T>.Name). Use it to filter events to only the settings your tool cares about.

Full Example

[Export(typeof(IGuiTool))]
[Name("Base64 Encoder / Decoder")]
// ... other attributes ...
internal sealed class Base64GuiTool : IGuiTool
{
    // Declare settings as static readonly fields for zero-overhead reuse.
    private static readonly SettingDefinition<bool> s_useUtf8 =
        new(name: "Base64EncoderDecoder.UseUtf8", defaultValue: true);

    private static readonly SettingDefinition<Base64Encoding> s_encodingMode =
        new(
            name: "Base64EncoderDecoder.EncodingMode",
            defaultValue: Base64Encoding.Standard,
            serialize: e => e.ToString(),
            deserialize: s => Enum.Parse<Base64Encoding>(s));

    [Import]
    private ISettingsProvider _settingsProvider = null!;

    public UIToolView View => new UIToolView(BuildUi());

    private IUIElement BuildUi()
    {
        bool useUtf8 = _settingsProvider.GetSetting(s_useUtf8);

        return GUI.VerticalStack().WithChildren(
            GUI.Switch()
                .OnText("UTF-8")
                .OffText("ASCII")
                .On(useUtf8)
                .OnToggle(isOn =>
                {
                    _settingsProvider.SetSetting(s_useUtf8, isOn);
                }));
    }

    public void OnDataReceived(string dataTypeName, object? parsedData) { }
}
Subscribe to SettingChanged when two tools share a setting and you want both UIs to stay in sync. Filter by comparing args.SettingName with settingDefinition.Name.

See Also

Build docs developers (and LLMs) love