Class ConfigFile
A simple implementation of IJsonFile for use with config files.
public abstract class ConfigFile : IJsonFile
- Inheritance
-
ConfigFile
- Implements
- Inherited Members
- Extension Methods
Constructors
ConfigFile()
Creates a new instance of ConfigFile, parsing the filename and subfolder from a
ConfigFileAttribute if declared, or with default values otherwise.
public ConfigFile()
ConfigFile(string, string)
Creates a new instance of ConfigFile.
protected ConfigFile(string fileName = "config", string subfolder = null)
Parameters
fileName
string- The name of the ConfigFile, "config" by default.
subfolder
string- Optional subfolder for the ConfigFile.
Examples
using Nautilus.Options;
using UnityEngine;
public class MyConfig : ConfigFile
{
public KeyCode ActivationKey { get; set; } = KeyCode.Escape;
public MyConfig() : base("options", "Config Files") { }
// The config file will be stored at the path "QMods\YourModName\Config Files\options.json"
}
Fields
OnFinishedLoading
An event that is invoked whenever the ConfigFile has finished loading data from disk.
[JsonIgnore]
public EventHandler<ConfigFileEventArgs> OnFinishedLoading
Field Value
OnFinishedSaving
An event that is invoked whenever the ConfigFile has finished saving data to disk.
[JsonIgnore]
public EventHandler<ConfigFileEventArgs> OnFinishedSaving
Field Value
OnStartedLoading
An event that is invoked whenever the ConfigFile is about to load data from disk.
[JsonIgnore]
public EventHandler<ConfigFileEventArgs> OnStartedLoading
Field Value
OnStartedSaving
An event that is invoked whenever the ConfigFile is about to save data to disk.
[JsonIgnore]
public EventHandler<ConfigFileEventArgs> OnStartedSaving
Field Value
Properties
AlwaysIncludedJsonConverters
The Newtonsoft.Json.JsonConverters that should always be used when reading/writing JSON data.
public JsonConverter[] AlwaysIncludedJsonConverters { get; }
Property Value
- JsonConverter[]
- See Also
JsonFilePath
The file path at which the JSON file is accessible for reading and writing.
public string JsonFilePath { get; }
Property Value
Methods
Load(bool)
Loads the JSON properties from the file on disk into the ConfigFile.
public void Load(bool createFileIfNotExist = true)
Parameters
createFileIfNotExist
bool- Whether a new JSON file should be created with default values if it does not already exist.
- See Also
LoadWithConverters(bool, params JsonConverter[])
Loads the JSON properties from the file on disk into the ConfigFile.
public void LoadWithConverters(bool createFileIfNotExist = true, params JsonConverter[] jsonConverters)
Parameters
createFileIfNotExist
bool- Whether a new JSON file should be created with default values if it does not already exist.
jsonConverters
JsonConverter[]- Optional Newtonsoft.Json.JsonConverters to be used for serialization. The AlwaysIncludedJsonConverters will always be used, regardless of whether you pass them.
- See Also
Save()
Saves the current fields and properties of the ConfigFile as JSON properties to the file on disk.
public void Save()
- See Also
SaveWithConverters(params JsonConverter[])
Saves the current fields and properties of the ConfigFile as JSON properties to the file on disk.
public void SaveWithConverters(params JsonConverter[] jsonConverters)
Parameters
jsonConverters
JsonConverter[]- Optional Newtonsoft.Json.JsonConverters to be used for deserialization. The AlwaysIncludedJsonConverters will always be used, regardless of whether you pass them.
- See Also