28 lines
790 B
C#
28 lines
790 B
C#
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace Knoks.Framework.Extentions
|
|
{
|
|
public static class ConfigurationExtensions
|
|
{
|
|
public static T Load<T>(this IConfiguration config) where T : new()
|
|
{
|
|
return config.Load(typeof(T).Name, new T());
|
|
}
|
|
|
|
public static T Load<T>(this IConfiguration config, string key) where T : new()
|
|
{
|
|
return config.Load(key, new T());
|
|
}
|
|
|
|
public static T Load<T>(this IConfiguration config, T instance)
|
|
{
|
|
return config.Load(typeof(T).Name, instance);
|
|
}
|
|
|
|
public static T Load<T>(this IConfiguration config, string key, T instance)
|
|
{
|
|
config.GetSection(key).Bind(instance);
|
|
return instance;
|
|
}
|
|
}
|
|
} |