Aether Utilities Aether Utilities
Aether Utilities Aether Utilities
DocFX + Singulink = ♥

Search Results for

    Edit this page

    Class ConfigManager<T>

    Namespace
    AetherUtils.Core.Configuration
    Assembly
    AetherUtils.Core.dll
    Provides methods for saving, loading, and querying a generic YAML configuration.
    public class ConfigManager<T> where T : class, new()

    Type Parameters

    T
    The DTO class that represents the configuration.
    Inheritance
    object
    ConfigManager<T>
    Derived
    DefaultConfigManager
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Extension Methods
    TypeExtensions.CanSerializeJson<T>(T)
    TypeExtensions.CanSerializeXml<T>(T)
    TypeExtensions.SerializeJson<T>(T)
    TypeExtensions.SerializeXml<T>(T)

    Remarks

    The custom class should have its properties related to configuration marked with a ConfigAttribute. These properties are the only ones which will be serialized and de-serialized from disk.

    Constructors

    ConfigManager(string)

    Create a configuration manager with the specified config file.
    public ConfigManager(string configFilePath)

    Parameters

    configFilePath string
    The full path to a configuration file to save and/or load.

    Properties

    ConfigExists

    Get a value indicating whether the configuration file exists on disk.
    public bool ConfigExists { get; }

    Property Value

    bool

    ConfigFilePath

    Get or set the path to the configuration file on disk.
    public string? ConfigFilePath { get; set; }

    Property Value

    string

    CurrentConfig

    Get or set the current configuration.
    [UsedImplicitly]
    public T? CurrentConfig { get; set; }

    Property Value

    T

    IsInitialized

    Get a value indicating whether the configuration has been initialized.
    public bool IsInitialized { get; }

    Property Value

    bool

    Methods

    CreateDefaultConfig()

    Create the default configuration.
    [UsedImplicitly]
    public virtual bool CreateDefaultConfig()

    Returns

    bool

    Get(ConfigOption)

    Get a configuration value specified by the configuration option.
    public object? Get(ConfigOption option)

    Parameters

    option ConfigOption
    The ConfigOption containing information about the value to get.

    Returns

    object
    The configuration value or null if the value did not exist.

    Get(string)

    Get a configuration value specified by configName.
    public object? Get(string configName)

    Parameters

    configName string
    The name of the configuration to get.

    Returns

    object
    The configuration value or null if the value did not exist.

    GetConfig()

    Get the current configuration as an object.
    [UsedImplicitly]
    public T? GetConfig()

    Returns

    T
    The current configuration or null if not initialized.

    Load(bool)

    Load a configuration file from disk based on the ConfigFilePath.
    public bool Load(bool applyDefaults = false)

    Parameters

    applyDefaults bool
    Indicates whether the default values should be applied to the loaded configuration.

    Returns

    bool
    true if the config loaded successfully; false otherwise.

    Exceptions

    ArgumentException
    If ConfigFilePath is null or empty.
    FileNotFoundException
    If the configuration file specified by ConfigFilePath was not found on disk.

    LoadAsync(bool)

    Asynchronously load a configuration file from disk based on the ConfigFilePath.
    public Task<bool> LoadAsync(bool applyDefaults = false)

    Parameters

    applyDefaults bool
    Indicates whether the default values should be applied to the loaded configuration.

    Returns

    Task<bool>
    true if the config loaded successfully; false otherwise.

    Exceptions

    ArgumentException
    If ConfigFilePath is null or empty.
    FileNotFoundException
    If the configuration file specified by ConfigFilePath was not found on disk.

    Save()

    Save a configuration file to disk based on the CurrentConfig and the ConfigFilePath.
    public bool Save()

    Returns

    bool
    true if the config saved successfully; false otherwise.

    Exceptions

    ArgumentException
    If ConfigFilePath is null or empty.

    SaveAsync()

    Asynchronously save a configuration file to disk based on the CurrentConfig and the ConfigFilePath.
    public Task<bool> SaveAsync()

    Returns

    Task<bool>
    true if the config saved successfully; false otherwise.

    Exceptions

    ArgumentException
    If ConfigFilePath is null or empty.

    Set(ConfigOption)

    Set a configuration value specified by the configuration option.
    public bool Set(ConfigOption option)

    Parameters

    option ConfigOption
    The ConfigOption containing information about the value to set.

    Returns

    bool
    true if the value was set successfully; false otherwise.

    Set(string, object?)

    Set a configuration value specified by configName.
    [UsedImplicitly]
    public bool Set(string configName, object? value)

    Parameters

    configName string
    The name of the configuration to set.
    value object
    The value to set.

    Returns

    bool
    true if the value was set successfully; false otherwise.

    SetConfig(T?)

    Set the current configuration object. This is more convenient than setting each property manually using Set(ConfigOption).
    [UsedImplicitly]
    public void SetConfig(T? config)

    Parameters

    config T
    The configuration object to set the internal config to.
    (c) 2024 Ethan Hann. All rights reserved.