Adds Configuration Manager + tests
This commit is contained in:
parent
55e65a1b21
commit
384cc3c6fd
16 changed files with 657 additions and 137 deletions
28
Core/Configurations/ConfigurationManager/Class1.cs
Normal file
28
Core/Configurations/ConfigurationManager/Class1.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using Configuration.Core;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Core.Configurations.ConfigurationManager
|
||||
{
|
||||
public static class ConfigurationExtensions
|
||||
{
|
||||
public static T Get<T>(this IConfigurationSection section) where T : class
|
||||
{
|
||||
if (section is JsonConfigurationSection jsonSection)
|
||||
{
|
||||
var token = jsonSection.GetToken();
|
||||
return token?.ToObject<T>();
|
||||
}
|
||||
throw new InvalidOperationException("Section is not a JsonConfigurationSection");
|
||||
}
|
||||
|
||||
public static T GetValue<T>(this IConfigurationSection section, string key)
|
||||
{
|
||||
if (section is JsonConfigurationSection jsonSection)
|
||||
{
|
||||
var token = jsonSection.GetToken().SelectToken(key.Replace(":", "."));
|
||||
return token.ToObject<T>();
|
||||
}
|
||||
throw new InvalidOperationException("Section is not a JsonConfigurationSection");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue