WIP on Config Handling
This commit is contained in:
parent
4dc03f2cbf
commit
8e6492e979
17 changed files with 314 additions and 288 deletions
|
|
@ -0,0 +1,27 @@
|
|||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Core.Configurations.SmartConfiguration
|
||||
{
|
||||
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