Skip to content

Commit

Permalink
configureOptions are non-nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkoshevoi committed Oct 3, 2021
1 parent 4f9e6d7 commit 5dac613
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static class ConfigurationBinder
/// <returns>The new instance of T if successful, default(T) otherwise.</returns>
[RequiresUnreferencedCode(TrimmingWarningMessage)]
public static T? Get<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration)
=> configuration.Get<T>(null);
=> configuration.Get<T>(_ => { });

/// <summary>
/// Attempts to bind the configuration instance to a new instance of type T.
Expand All @@ -42,12 +42,16 @@ public static class ConfigurationBinder
/// <param name="configureOptions">Configures the binder options.</param>
/// <returns>The new instance of T if successful, default(T) otherwise.</returns>
[RequiresUnreferencedCode(TrimmingWarningMessage)]
public static T? Get<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration, Action<BinderOptions>? configureOptions)
public static T? Get<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration, Action<BinderOptions> configureOptions)
{
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}
if (configureOptions is null)
{
throw new ArgumentNullException(nameof(configureOptions));
}

object? result = configuration.Get(typeof(T), configureOptions);
if (result == null)
Expand All @@ -67,7 +71,7 @@ public static class ConfigurationBinder
/// <returns>The new instance if successful, null otherwise.</returns>
[RequiresUnreferencedCode(TrimmingWarningMessage)]
public static object? Get(this IConfiguration configuration, Type type)
=> configuration.Get(type, null);
=> configuration.Get(type, _ => { });

/// <summary>
/// Attempts to bind the configuration instance to a new instance of type T.
Expand All @@ -83,15 +87,15 @@ public static class ConfigurationBinder
this IConfiguration configuration,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Type type,
Action<BinderOptions>? configureOptions)
Action<BinderOptions> configureOptions)
{
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}

var options = new BinderOptions();
configureOptions?.Invoke(options);
configureOptions(options);
return BindInstance(type, instance: null, config: configuration, options: options);
}

Expand Down

0 comments on commit 5dac613

Please sign in to comment.