diff --git a/DisCatSharp.Configuration/Models/ConfigSection.cs b/DisCatSharp.Configuration/Models/ConfigSection.cs index 0c960b913..c64b8c71a 100644 --- a/DisCatSharp.Configuration/Models/ConfigSection.cs +++ b/DisCatSharp.Configuration/Models/ConfigSection.cs @@ -1,82 +1,81 @@ // This file is part of the DisCatSharp project, a fork of DSharpPlus. // // Copyright (c) 2021 AITSYS // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. using Microsoft.Extensions.Configuration; namespace DisCatSharp.Configuration.Models { /// /// Represents an object in /// internal readonly struct ConfigSection { /// /// Key within which represents an object containing multiple values /// public string SectionName { get;} /// /// Optional used to indicate this section is nested within another /// public string? Root { get; } /// /// Reference to used within application /// public IConfiguration Config { get; } /// Reference to config /// Section of interest /// (Optional) Indicates is nested within this name. Default value is DisCatSharp public ConfigSection(ref IConfiguration config, string sectionName, string? rootName = "DisCatSharp") { this.Config = config; this.SectionName = sectionName; this.Root = rootName; } /// /// Checks if key exists in /// /// Property / Key to search for in section /// Config path to key - /// (Optional) Root key to use. Default is DisCatSharp because configs in library should be consolidated /// True if key exists, otherwise false. Outputs path to config regardless public bool ContainsKey(string name, out string path) { path = string.IsNullOrEmpty(this.Root) ? this.Config.ConfigPath(this.SectionName, name) : this.Config.ConfigPath(this.Root, this.SectionName, name); return !string.IsNullOrEmpty(this.Config[path]); } /// /// Attempts to get value associated to the config path.
Should be used in unison with ///
/// Config path to value /// Value found at public string GetValue(string path) => this.Config[path]; } }