Configs and DataStorage

On this page we will explain the built in config system as well as the predefinied data directory for your plugin.

Configs using TOML

The built in config system of Onsharp uses the file format TOML which is a vartion of YAML and INI. The creation as well as the loading of the config will be managed by Onsharp itself. You just need to define a data class, and let Onsharp load this class.

using Onsharp.IO;

namespace Tutorial
{
    [Config("myconfig")]
    public class MyConfig
    {
        public bool IsDebug { get; set; } = false;
    }
}

This data class is marked with the config attribute. You must define the name of the config file with the first parameter. The second parameter is optional and can define a sub directory.

Now you just need to register the config:

using Onsharp.Plugins;

namespace Tutorial
{
    public class PluginMain : Plugin
    {
        public override void OnStart()
        {
             //Your start up logic here
             MyConfig config = Data.Config<MyConfig>(); 
        }
        
        public override void OnStop()
        {
            //Your stop and clean up logic here
        }  
    }
}

The config file gets automatically created in the data folder of the plugin and than loaded and returned.

Data Storage

The data storage is not fully implemented currently. If you just want to write some kind of file to your data folder, you can access the directory info via Data.Directory

Last updated