Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bind<T> APIs (drafted) #38

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public static partial class ConfigurationBinder
public static void Bind(this Microsoft.Extensions.Configuration.IConfiguration configuration, object instance) { }
public static void Bind(this Microsoft.Extensions.Configuration.IConfiguration configuration, object instance, System.Action<Microsoft.Extensions.Configuration.BinderOptions> configureOptions) { }
public static void Bind(this Microsoft.Extensions.Configuration.IConfiguration configuration, string key, object instance) { }
public static void Bind<T>(this Microsoft.Extensions.Configuration.IConfiguration configuration, string key, T instance) { }
public static void Bind<T>(this Microsoft.Extensions.Configuration.IConfiguration configuration, T instance) { }
public static void Bind<T>(this Microsoft.Extensions.Configuration.IConfiguration configuration, T instance, System.Action<Microsoft.Extensions.Configuration.BinderOptions> configureOptions) { }
public static object Get(this Microsoft.Extensions.Configuration.IConfiguration configuration, System.Type type) { throw null; }
public static object Get(this Microsoft.Extensions.Configuration.IConfiguration configuration, System.Type type, System.Action<Microsoft.Extensions.Configuration.BinderOptions> configureOptions) { throw null; }
public static object GetValue(this Microsoft.Extensions.Configuration.IConfiguration configuration, System.Type type, string key) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ public static object Get(this IConfiguration configuration, Type type, Action<Bi
return BindInstance(type, instance: null, config: configuration, options: options);
}

/// <summary>
/// TODO add
/// </summary>
public static void Bind<T>(this IConfiguration configuration, string key, T instance)
=> configuration.GetSection(key).Bind<T>(instance);

/// <summary>
/// TODO add
/// </summary>
public static void Bind<T>(this IConfiguration configuration, T instance)
=> configuration.Bind<T>(instance, o => { });

/// <summary>
/// TODO add
/// </summary>
public static void Bind<T>(this IConfiguration configuration, T instance, Action<BinderOptions> configureOptions)
=> configuration.Bind((object)instance, configureOptions);

/// <summary>
/// Attempts to bind the given object instance to the configuration section specified by the key by matching property names against configuration keys recursively.
/// </summary>
Expand Down