Avalonia Code OnlyItaliano

API › RAVAL

RSettings class

public abstract class RSettings

The settings of an application, read and written in a file.

Properties

string Path { get; }

The file of the settings.

bool AddMissing { get; set; }

Whether a key read and not found is written with its default (true).

bool AutoSave { get; set; }

Whether the file is saved by itself after a change (true).

int SaveDelayMs { get; set; }

How long after the last change the file is saved, milliseconds (500).

bool Dirty { get; }

Whether there are changes not yet written.

Methods

static RSettings Open(string path)

The settings of a file, already read: INI for «.ini», JSON for every other extension. A missing file is not an error: it is created at the first save.

static string Folder(string app)

The folder of the settings of an application, created if missing: %APPDATA%\app on Windows, ~/.config/app on Linux and macOS (what .NET gives for ApplicationData).

string GetString(string key, string def)

A text value (the default if the key is missing).

int GetInt(string key, int def)

An integer value (the default if missing or not a number).

double GetDouble(string key, double def)

A real value, written with the point (the default if missing or not a number).

bool GetBool(string key, bool def)

A yes/no value: true, yes, on, 1 and false, no, off, 0 (the default otherwise).

List<string> GetList(string key)

A list of texts (empty if the key is missing; a missing list is not added).

bool Contains(string key)

Whether the key is in the file.

void Set(string key, string value)

Writes a text value.

void Set(string key, int value)

Writes an integer value.

void Set(string key, double value)

Writes a real value, with the point and all its digits.

void Set(string key, bool value)

Writes a yes/no value.

void SetList(string key, IEnumerable<string> values)

Writes a list of texts.

void Remove(string key)

Removes a key (value or list); nothing if it is not there.

List<string> Keys()

The keys of the values in the file, with their full path, in file order.

bool Load()

Reads the file again, forgetting what is not saved; false if it was damaged.

void Save()

Writes the file now, if something changed (a temporary file, then renamed).

Events

event Action<string> Changed

After Set has changed a value, with its key (on the thread that called Set).