Utility.Extensions.Configuration.Yaml by JP Dillingham

<PackageReference Include="Utility.Extensions.Configuration.Yaml" Version="1.0.1" />

 YamlConfigurationProvider

using Microsoft.Extensions.Configuration; using System; using System.Collections.Generic; using System.IO; using System.Linq; using YamlDotNet.Core; using YamlDotNet.RepresentationModel; namespace Utility.Extensions.Configuration.Yaml { public class YamlConfigurationProvider : FileConfigurationProvider { private string[] NullValues { get; } = new string[3] { "~", "null", "" }; public YamlConfigurationProvider(YamlConfigurationSource source) : base(source) { } public override void Load(Stream stream) { try { using (StreamReader streamReader = new StreamReader(stream)) { YamlStream val = new YamlStream(); val.Load((TextReader)streamReader); YamlMappingNode root = val.get_Documents()[0].get_RootNode(); Traverse(root, null); } } catch (YamlException val2) { YamlException innerException = val2; throw new FormatException("Could not parse the YAML file.", (Exception)innerException); } } private void Traverse(YamlNode root, string path = null) { YamlScalarNode val = root as YamlScalarNode; if (val != null) { if (base.Data.ContainsKey(<Traverse>g__Clean|5_0(path))) throw new FormatException("A duplicate key '" + <Traverse>g__Clean|5_0(path) + "' was found."); base.Data[<Traverse>g__Clean|5_0(path)] = (NullValues.Contains(val.get_Value().ToLower()) ? null : val.get_Value()); } else { YamlMappingNode val2 = root as YamlMappingNode; if (val2 != null) { foreach (KeyValuePair<YamlNode, YamlNode> item in (IEnumerable<KeyValuePair<YamlNode, YamlNode>>)val2.get_Children()) { string text = <Traverse>g__Clean|5_0(item.Key.get_Value()); Traverse(item.Value, (path == null) ? text : ConfigurationPath.Combine(path, text)); } } else { YamlSequenceNode val3 = root as YamlSequenceNode; if (val3 != null) { for (int i = 0; i < val3.get_Children().Count(); i++) { Traverse(val3.get_Children()[i], ConfigurationPath.Combine(path, i.ToString())); } } } } } } }