Adds Configuration Manager + tests
This commit is contained in:
parent
55e65a1b21
commit
384cc3c6fd
16 changed files with 657 additions and 137 deletions
|
|
@ -0,0 +1,31 @@
|
|||
using Newtonsoft.Json.Linq;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using System.Data;
|
||||
|
||||
namespace Configuration.Core;
|
||||
public class JsonConfiguration : IConfiguration
|
||||
{
|
||||
private readonly JObject _data;
|
||||
private readonly IChangeToken _changeToken;
|
||||
|
||||
public JsonConfiguration(JObject data, IChangeToken changeToken)
|
||||
{
|
||||
_data = data;
|
||||
_changeToken = changeToken;
|
||||
}
|
||||
|
||||
public string this[string key]
|
||||
{
|
||||
get => _data.SelectToken(key.Replace(":", "."))?.ToString();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IConfigurationSection GetSection(string key) =>
|
||||
new JsonConfigurationSection(_data, key);
|
||||
|
||||
public IEnumerable<IConfigurationSection> GetChildren() =>
|
||||
_data.Properties().Select(p => new JsonConfigurationSection(_data, p.Name));
|
||||
|
||||
public IChangeToken GetReloadToken() => _changeToken;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue