SettingsFile

References
public sealed class SettingsFile
A class for caching settings which are stored in a file.

Constructors

SettingsFile

#
public SettingsFile(string file)
Create a new settings file which mirrors a file on the disk.
file (string)

Fields

Extension

#
public const string Extension = ".ghs"
Gets the file extension under which grasshopper settings files are stored.

Properties

File

#
public string File { get; }
Gets the file path this settings file points to. The file may or may not exist.

Node

#
public Node Node { get; }
Gets the underlying node which stores the values. Careful when using this object directly, you may for example not overwrite existing values, you must delete them first. Also, changes made directly to the node will not cause a settings file update.

Methods

Clear

#
public void Clear()
Clear all settings.

Get

#
public bool Get(string name, bool default)
Retrieve a bool from the cached settings.
name (string)Name of setting to retrieve.
default (bool)Default value in case name isn't available, or doesn't represent a boolean.
Boolean value of setting or the default if the setting isn't known.

Get

#
public Color Get(string name, Color default)
Retrieve a colour from the cached settings.
name (string)Name of setting to retrieve.
default (Color)Default value in case name isn't available, or doesn't represent a colour.
Id value of setting or the default if the setting isn't known.

Get

#
public DateTime Get(string name, DateTime default)
Retrieve a date from the cached settings.
name (string)Name of setting to retrieve.
default (DateTime)Default value in case name isn't available, or doesn't represent a date.
Id value of setting or the default if the setting isn't known.

Get

#
public double Get(string name, double default)
Retrieve a number from the cached settings.
name (string)Name of setting to retrieve.
default (double)Default value in case name isn't available, or doesn't represent a number.
Numeric value of setting or the default if the setting isn't known.

Get

#
public float Get(string name, float default)
Retrieve a number from the cached settings.
name (string)Name of setting to retrieve.
default (float)Default value in case name isn't available, or doesn't represent a number.
Numeric value of setting or the default if the setting isn't known.

Get

#
public Guid Get(string name, Guid default)
Retrieve a GUID from the cached settings.
name (string)Name of setting to retrieve.
default (Guid)Default value in case name isn't available, or doesn't represent a guid.
Id value of setting or the default if the setting isn't known.

Get

#
public int Get(string name, int default)
Retrieve an integer from the cached settings.
name (string)Name of setting to retrieve.
default (int)Default value in case name isn't available, or doesn't represent an integer.
Integer value of setting or the default if the setting isn't known.

Get

#
public IStorable Get(string name, IStorable default)
Retrieve a colour from the cached settings.
name (string)Name of setting to retrieve.
default (IStorable)Default value in case name isn't available, or doesn't represent a colour.
Id value of setting or the default if the setting isn't known.

Get

#
public PointF Get(string name, PointF default)
Retrieve a point from the cached settings.
name (string)Name of setting to retrieve.
default (PointF)Default value in case name isn't available, or doesn't represent a point.
Point value of setting or the default if the setting isn't known.

Get

#
public RectangleF Get(string name, RectangleF default)
Retrieve a rectangle from the cached settings.
name (string)Name of setting to retrieve.
default (RectangleF)Default value in case name isn't available, or doesn't represent a rectangle.
Rectangle value of setting or the default if the setting isn't known.

Get

#
public SizeF Get(string name, SizeF default)
Retrieve a size from the cached settings.
name (string)Name of setting to retrieve.
default (SizeF)Default value in case name isn't available, or doesn't represent a size.
Point value of setting or the default if the setting isn't known.

Get

#
public string Get(string name, string default)
Retrieve a string from the cached settings.
name (string)Name of setting to retrieve.
default (string)Default value in case name isn't available.
String value of setting or the default if the setting isn't known.

Get

#
public TimeSpan Get(string name, TimeSpan default)
Retrieve a time span from the cached settings.
name (string)Name of setting to retrieve.
default (TimeSpan)Default value in case name isn't available, or doesn't represent a time span.
Id value of setting or the default if the setting isn't known.

InDefaultFolder

#
public static SettingsFile InDefaultFolder(string name)
Create or load a settings file by name in the default Grasshopper 2.0 settings folder.
name (string)Name of settings to load.
Settings file.

Rename

#
public bool Rename(string oldName, string newName)
Attempt to rename a setting. If another setting with the newName already exists, it will be removed, even if the oldName does not point to an existing setting.
oldName (string)Old name of setting.
newName (string)New name of setting.
True if setting was renamed, or if conflicting setting was removed.

Set

#
public void Set(string name, bool value)
Store a boolean in the cached settings.
name (string)Name of setting to store.
value (bool)Value to store.

Set

#
public void Set(string name, Color value)
Store a color in the cached settings.
name (string)Name of setting to store.
value (Color)Value to store.

Set

#
public void Set(string name, DateTime value)
Store a date in the cached settings.
name (string)Name of setting to store.
value (DateTime)Value to store.

Set

#
public void Set(string name, double value)
Store a number in the cached settings.
name (string)Name of setting to store.
value (double)Value to store.

Set

#
public void Set(string name, float value)
Store a number in the cached settings.
name (string)Name of setting to store.
value (float)Value to store.

Set

#
public void Set(string name, Guid value)
Store a guid in the cached settings.
name (string)Name of setting to store.
value (Guid)Value to store.

Set

#
public void Set(string name, int value)
Store an integer in the cached settings.
name (string)Name of setting to store.
value (int)Value to store.

Set

#
public void Set(string name, IStorable value)
Store an IStorable object in the cached settings.
name (string)Name of setting to store.
value (IStorable)Value to store.

Set

#
public void Set(string name, PointF value)
Store a point in the cached settings.
name (string)Name of setting to store.
value (PointF)Value to store.

Set

#
public void Set(string name, RectangleF value)
Store a rectangle in the cached settings.
name (string)Name of setting to store.
value (RectangleF)Value to store.

Set

#
public void Set(string name, SizeF value)
Store a size in the cached settings.
name (string)Name of setting to store.
value (SizeF)Value to store.

Set

#
public void Set(string name, string value)
Store a string in the cached settings.
name (string)Name of setting to store.
value (string)Value to store.

Set

#
public void Set(string name, TimeSpan value)
Store a time span in the cached settings.
name (string)Name of setting to store.
value (TimeSpan)Value to store.

TryLoadSettingsFromFile

#
public bool TryLoadSettingsFromFile()
Load the settings form the file. This happens automatically on construction, so you only need to call this method if you have reason to believe the settings file was modified by a process other than this SettingsFile.

TrySaveSettingsToFile

#
public bool TrySaveSettingsToFile()
Write the current state of this SettingsFile to the file on the disk.