@@ -56,6 +56,15 @@ public static object Get(this IConfiguration configuration, Type type)
5656 return BindInstance ( type , instance : null , config : configuration ) ;
5757 }
5858
59+ /// <summary>
60+ /// Attempts to bind the given object instance to the configuration section specified by the key by matching property names against configuration keys recursively.
61+ /// </summary>
62+ /// <param name="configuration">The configuration instance to bind.</param>
63+ /// <param name="sectionKey">The key of the configuration section to bind.</param>
64+ /// <param name="instance">The object to bind.</param>
65+ public static void Bind ( this IConfiguration configuration , string sectionKey , object instance )
66+ => configuration . GetSection ( sectionKey ) . Bind ( instance ) ;
67+
5968 /// <summary>
6069 /// Attempts to bind the given object instance to configuration values by matching property names against configuration keys recursively.
6170 /// </summary>
@@ -79,49 +88,49 @@ public static void Bind(this IConfiguration configuration, object instance)
7988 /// </summary>
8089 /// <typeparam name="T">The type to convert the value to.</typeparam>
8190 /// <param name="configuration">The configuration.</param>
82- /// <param name="key ">The configuration key for the value to convert.</param>
91+ /// <param name="sectionKey ">The key of the configuration section's value to convert.</param>
8392 /// <returns>The converted value.</returns>
84- public static T GetValue < T > ( this IConfiguration configuration , string key )
93+ public static T GetValue < T > ( this IConfiguration configuration , string sectionKey )
8594 {
86- return GetValue ( configuration , key , default ( T ) ) ;
95+ return GetValue ( configuration , sectionKey , default ( T ) ) ;
8796 }
8897
8998 /// <summary>
9099 /// Extracts the value with the specified key and converts it to type T.
91100 /// </summary>
92101 /// <typeparam name="T">The type to convert the value to.</typeparam>
93102 /// <param name="configuration">The configuration.</param>
94- /// <param name="key ">The configuration key for the value to convert.</param>
103+ /// <param name="sectionKey ">The key of the configuration section's value to convert.</param>
95104 /// <param name="defaultValue">The default value to use if no value is found.</param>
96105 /// <returns>The converted value.</returns>
97- public static T GetValue < T > ( this IConfiguration configuration , string key , T defaultValue )
106+ public static T GetValue < T > ( this IConfiguration configuration , string sectionKey , T defaultValue )
98107 {
99- return ( T ) GetValue ( configuration , typeof ( T ) , key , defaultValue ) ;
108+ return ( T ) GetValue ( configuration , typeof ( T ) , sectionKey , defaultValue ) ;
100109 }
101110
102111 /// <summary>
103112 /// Extracts the value with the specified key and converts it to the specified type.
104113 /// </summary>
105114 /// <param name="configuration">The configuration.</param>
106115 /// <param name="type">The type to convert the value to.</param>
107- /// <param name="key ">The configuration key for the value to convert.</param>
116+ /// <param name="sectionKey ">The key of the configuration section's value to convert.</param>
108117 /// <returns>The converted value.</returns>
109- public static object GetValue ( this IConfiguration configuration , Type type , string key )
118+ public static object GetValue ( this IConfiguration configuration , Type type , string sectionKey )
110119 {
111- return GetValue ( configuration , type , key , defaultValue : null ) ;
120+ return GetValue ( configuration , type , sectionKey , defaultValue : null ) ;
112121 }
113122
114123 /// <summary>
115124 /// Extracts the value with the specified key and converts it to the specified type.
116125 /// </summary>
117126 /// <param name="configuration">The configuration.</param>
118127 /// <param name="type">The type to convert the value to.</param>
119- /// <param name="key ">The configuration key for the value to convert.</param>
128+ /// <param name="sectionKey ">The key of the configuration section's value to convert.</param>
120129 /// <param name="defaultValue">The default value to use if no value is found.</param>
121130 /// <returns>The converted value.</returns>
122- public static object GetValue ( this IConfiguration configuration , Type type , string key , object defaultValue )
131+ public static object GetValue ( this IConfiguration configuration , Type type , string sectionKey , object defaultValue )
123132 {
124- var value = configuration . GetSection ( key ) . Value ;
133+ var value = configuration . GetSection ( sectionKey ) . Value ;
125134 if ( value != null )
126135 {
127136 return ConvertValue ( type , value ) ;
0 commit comments