Consider overload of Get<T> that accepts child section name
It'd be nice to have a Get<T>(string section) that looks like this:
namespace Microsoft.Extensions.Configuration
{
public static class ConfigurationExtensions
{
public static T Get<T>(this IConfiguration section, string key)
{
return section.GetSection(key).Get<T>();
}
}
}
This would be very useful. Alternatively, it would be good to have support for arbitrary nesting like so:
Configuration["level1"]["level2"] or
Configuration["level1.level2"] or
Configuration["level1//level2"]
@brockallen I believe this method is now available thanks to @HaoK.
public static T GetValue<T>(this IConfiguration configuration, string key)
{
return GetValue(configuration, key, default(T));
}
Does not work, the GetValue is just for string and primites, use following 'hack'
var settings = new MySectionConf();
Config.GetSection(nameof(MySectionConf)).Bind(settings); or Config.GetSection("customKey").Bind(settings);
return settings;
Tagging subscribers to this area: @eiriktsarpalis Notify danmosemsft if you want to be subscribed.
Due to lack of recent activity
I think there's no activity since this was opened... ~8 years ago. In any event, this still feels like it would be useful, and I've not seen a reason why it's not feasible or a good idea.
Triage: sounds an interesting convenience method, we may consider it in future.