From bf0492f520c2530c4cc475849e74bf55541e52b8 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Fri, 11 Feb 2022 18:34:13 +0200 Subject: [PATCH] [Group 2] Enable nullable annotations for `Microsoft.Extensions.Options` (#63767) * Everithing but ref * Update ValidateOptions.cs * Update ref * ConfigureNamedOptions TDep is notnull * PostConfigureOptions Tdep is notnull * OptionsMonitor.OnChange name is notnull * Revert non-nullable changes * Fix invalid ref * Failures notnull only when Failed * FailureMessage is notnull * Validation is nonnull * Update OptionsValidationTests.cs * OptionsFactory.Create name is nonnull --- .../ref/Microsoft.Extensions.Options.cs | 202 +++++++++++---------- .../ref/Microsoft.Extensions.Options.csproj | 1 + .../src/ConfigureNamedOptions.cs | 48 ++--- .../src/ConfigureOptions.cs | 4 +- .../src/IConfigureNamedOptions.cs | 2 +- .../src/IOptionsChangeTokenSource.cs | 2 +- .../src/IOptionsMonitor.cs | 4 +- .../src/IOptionsMonitorCache.cs | 6 +- .../src/IOptionsSnapshot.cs | 2 +- .../src/IPostConfigureOptions.cs | 2 +- .../src/IValidateOptions.cs | 2 +- .../src/Microsoft.Extensions.Options.csproj | 1 + .../src/OptionsBuilder.cs | 34 +++- .../src/OptionsCache.cs | 12 +- .../src/OptionsManager.cs | 4 +- .../src/OptionsMonitor.cs | 6 +- .../src/OptionsServiceCollectionExtensions.cs | 6 +- .../src/OptionsValidationException.cs | 2 +- .../src/OptionsWrapper.cs | 2 +- .../src/PostConfigureOptions.cs | 48 ++--- .../src/UnnamedOptionsManager.cs | 4 +- .../src/ValidateOptions.cs | 58 +++--- .../src/ValidateOptionsResult.cs | 7 +- .../OptionsValidationTests.cs | 15 ++ 24 files changed, 262 insertions(+), 212 deletions(-) diff --git a/src/libraries/Microsoft.Extensions.Options/ref/Microsoft.Extensions.Options.cs b/src/libraries/Microsoft.Extensions.Options/ref/Microsoft.Extensions.Options.cs index c596b9d..8b3dd4b 100644 --- a/src/libraries/Microsoft.Extensions.Options/ref/Microsoft.Extensions.Options.cs +++ b/src/libraries/Microsoft.Extensions.Options/ref/Microsoft.Extensions.Options.cs @@ -10,92 +10,92 @@ namespace Microsoft.Extensions.DependencyInjection { public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddOptions(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) { throw null; } public static Microsoft.Extensions.Options.OptionsBuilder AddOptions(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) where TOptions : class { throw null; } - public static Microsoft.Extensions.Options.OptionsBuilder AddOptions(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name) where TOptions : class { throw null; } + public static Microsoft.Extensions.Options.OptionsBuilder AddOptions(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string? name) where TOptions : class { throw null; } public static Microsoft.Extensions.DependencyInjection.IServiceCollection ConfigureAll(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configureOptions) where TOptions : class { throw null; } public static Microsoft.Extensions.DependencyInjection.IServiceCollection ConfigureOptions(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, object configureInstance) { throw null; } public static Microsoft.Extensions.DependencyInjection.IServiceCollection ConfigureOptions(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type configureType) { throw null; } public static Microsoft.Extensions.DependencyInjection.IServiceCollection ConfigureOptions<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] TConfigureOptions>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) where TConfigureOptions : class { throw null; } public static Microsoft.Extensions.DependencyInjection.IServiceCollection Configure(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configureOptions) where TOptions : class { throw null; } - public static Microsoft.Extensions.DependencyInjection.IServiceCollection Configure(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, System.Action configureOptions) where TOptions : class { throw null; } + public static Microsoft.Extensions.DependencyInjection.IServiceCollection Configure(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string? name, System.Action configureOptions) where TOptions : class { throw null; } public static Microsoft.Extensions.DependencyInjection.IServiceCollection PostConfigureAll(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configureOptions) where TOptions : class { throw null; } public static Microsoft.Extensions.DependencyInjection.IServiceCollection PostConfigure(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action configureOptions) where TOptions : class { throw null; } - public static Microsoft.Extensions.DependencyInjection.IServiceCollection PostConfigure(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, System.Action configureOptions) where TOptions : class { throw null; } + public static Microsoft.Extensions.DependencyInjection.IServiceCollection PostConfigure(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string? name, System.Action configureOptions) where TOptions : class { throw null; } } } namespace Microsoft.Extensions.Options { public partial class ConfigureNamedOptions : Microsoft.Extensions.Options.IConfigureNamedOptions, Microsoft.Extensions.Options.IConfigureOptions where TOptions : class { - public ConfigureNamedOptions(string name, System.Action action) { } - public System.Action Action { get { throw null; } } - public string Name { get { throw null; } } - public virtual void Configure(string name, TOptions options) { } + public ConfigureNamedOptions(string? name, System.Action? action) { } + public System.Action? Action { get { throw null; } } + public string? Name { get { throw null; } } + public virtual void Configure(string? name, TOptions options) { } public void Configure(TOptions options) { } } public partial class ConfigureNamedOptions : Microsoft.Extensions.Options.IConfigureNamedOptions, Microsoft.Extensions.Options.IConfigureOptions where TOptions : class where TDep : class { - public ConfigureNamedOptions(string name, TDep dependency, System.Action action) { } - public System.Action Action { get { throw null; } } + public ConfigureNamedOptions(string? name, TDep dependency, System.Action? action) { } + public System.Action? Action { get { throw null; } } public TDep Dependency { get { throw null; } } - public string Name { get { throw null; } } - public virtual void Configure(string name, TOptions options) { } + public string? Name { get { throw null; } } + public virtual void Configure(string? name, TOptions options) { } public void Configure(TOptions options) { } } public partial class ConfigureNamedOptions : Microsoft.Extensions.Options.IConfigureNamedOptions, Microsoft.Extensions.Options.IConfigureOptions where TOptions : class where TDep1 : class where TDep2 : class { - public ConfigureNamedOptions(string name, TDep1 dependency, TDep2 dependency2, System.Action action) { } - public System.Action Action { get { throw null; } } + public ConfigureNamedOptions(string? name, TDep1 dependency, TDep2 dependency2, System.Action? action) { } + public System.Action? Action { get { throw null; } } public TDep1 Dependency1 { get { throw null; } } public TDep2 Dependency2 { get { throw null; } } - public string Name { get { throw null; } } - public virtual void Configure(string name, TOptions options) { } + public string? Name { get { throw null; } } + public virtual void Configure(string? name, TOptions options) { } public void Configure(TOptions options) { } } public partial class ConfigureNamedOptions : Microsoft.Extensions.Options.IConfigureNamedOptions, Microsoft.Extensions.Options.IConfigureOptions where TOptions : class where TDep1 : class where TDep2 : class where TDep3 : class { - public ConfigureNamedOptions(string name, TDep1 dependency, TDep2 dependency2, TDep3 dependency3, System.Action action) { } - public System.Action Action { get { throw null; } } + public ConfigureNamedOptions(string? name, TDep1 dependency, TDep2 dependency2, TDep3 dependency3, System.Action? action) { } + public System.Action? Action { get { throw null; } } public TDep1 Dependency1 { get { throw null; } } public TDep2 Dependency2 { get { throw null; } } public TDep3 Dependency3 { get { throw null; } } - public string Name { get { throw null; } } - public virtual void Configure(string name, TOptions options) { } + public string? Name { get { throw null; } } + public virtual void Configure(string? name, TOptions options) { } public void Configure(TOptions options) { } } public partial class ConfigureNamedOptions : Microsoft.Extensions.Options.IConfigureNamedOptions, Microsoft.Extensions.Options.IConfigureOptions where TOptions : class where TDep1 : class where TDep2 : class where TDep3 : class where TDep4 : class { - public ConfigureNamedOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, System.Action action) { } - public System.Action Action { get { throw null; } } + public ConfigureNamedOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, System.Action? action) { } + public System.Action? Action { get { throw null; } } public TDep1 Dependency1 { get { throw null; } } public TDep2 Dependency2 { get { throw null; } } public TDep3 Dependency3 { get { throw null; } } public TDep4 Dependency4 { get { throw null; } } - public string Name { get { throw null; } } - public virtual void Configure(string name, TOptions options) { } + public string? Name { get { throw null; } } + public virtual void Configure(string? name, TOptions options) { } public void Configure(TOptions options) { } } public partial class ConfigureNamedOptions : Microsoft.Extensions.Options.IConfigureNamedOptions, Microsoft.Extensions.Options.IConfigureOptions where TOptions : class where TDep1 : class where TDep2 : class where TDep3 : class where TDep4 : class where TDep5 : class { - public ConfigureNamedOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, TDep5 dependency5, System.Action action) { } - public System.Action Action { get { throw null; } } + public ConfigureNamedOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, TDep5 dependency5, System.Action? action) { } + public System.Action? Action { get { throw null; } } public TDep1 Dependency1 { get { throw null; } } public TDep2 Dependency2 { get { throw null; } } public TDep3 Dependency3 { get { throw null; } } public TDep4 Dependency4 { get { throw null; } } public TDep5 Dependency5 { get { throw null; } } - public string Name { get { throw null; } } - public virtual void Configure(string name, TOptions options) { } + public string? Name { get { throw null; } } + public virtual void Configure(string? name, TOptions options) { } public void Configure(TOptions options) { } } public partial class ConfigureOptions : Microsoft.Extensions.Options.IConfigureOptions where TOptions : class { - public ConfigureOptions(System.Action action) { } - public System.Action Action { get { throw null; } } + public ConfigureOptions(System.Action? action) { } + public System.Action? Action { get { throw null; } } public virtual void Configure(TOptions options) { } } public partial interface IConfigureNamedOptions : Microsoft.Extensions.Options.IConfigureOptions where TOptions : class { - void Configure(string name, TOptions options); + void Configure(string? name, TOptions options); } public partial interface IConfigureOptions where TOptions : class { @@ -103,7 +103,7 @@ namespace Microsoft.Extensions.Options } public partial interface IOptionsChangeTokenSource { - string Name { get; } + string? Name { get; } Microsoft.Extensions.Primitives.IChangeToken GetChangeToken(); } public partial interface IOptionsFactory<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions> where TOptions : class @@ -113,19 +113,19 @@ namespace Microsoft.Extensions.Options public partial interface IOptionsMonitorCache<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions> where TOptions : class { void Clear(); - TOptions GetOrAdd(string name, System.Func createOptions); - bool TryAdd(string name, TOptions options); - bool TryRemove(string name); + TOptions GetOrAdd(string? name, System.Func createOptions); + bool TryAdd(string? name, TOptions options); + bool TryRemove(string? name); } public partial interface IOptionsMonitor<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] out TOptions> { TOptions CurrentValue { get; } - TOptions Get(string name); - System.IDisposable OnChange(System.Action listener); + TOptions Get(string? name); + System.IDisposable OnChange(System.Action listener); } public partial interface IOptionsSnapshot<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] out TOptions> : Microsoft.Extensions.Options.IOptions where TOptions : class { - TOptions Get(string name); + TOptions Get(string? name); } public partial interface IOptions<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] out TOptions> where TOptions : class { @@ -133,11 +133,11 @@ namespace Microsoft.Extensions.Options } public partial interface IPostConfigureOptions where TOptions : class { - void PostConfigure(string name, TOptions options); + void PostConfigure(string? name, TOptions options); } public partial interface IValidateOptions where TOptions : class { - Microsoft.Extensions.Options.ValidateOptionsResult Validate(string name, TOptions options); + Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, TOptions options); } public static partial class Options { @@ -146,7 +146,7 @@ namespace Microsoft.Extensions.Options } public partial class OptionsBuilder where TOptions : class { - public OptionsBuilder(Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name) { } + public OptionsBuilder(Microsoft.Extensions.DependencyInjection.IServiceCollection services, string? name) { } public string Name { get { throw null; } } public Microsoft.Extensions.DependencyInjection.IServiceCollection Services { get { throw null; } } public virtual Microsoft.Extensions.Options.OptionsBuilder Configure(System.Action configureOptions) { throw null; } @@ -163,24 +163,24 @@ namespace Microsoft.Extensions.Options public virtual Microsoft.Extensions.Options.OptionsBuilder PostConfigure(System.Action configureOptions) where TDep1 : class where TDep2 : class where TDep3 : class where TDep4 : class where TDep5 : class { throw null; } public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation) { throw null; } public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation, string failureMessage) { throw null; } - public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation) { throw null; } - public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation, string failureMessage) { throw null; } - public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation) { throw null; } - public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation, string failureMessage) { throw null; } - public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation) { throw null; } - public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation, string failureMessage) { throw null; } - public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation) { throw null; } - public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation, string failureMessage) { throw null; } - public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation) { throw null; } - public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation, string failureMessage) { throw null; } + public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation) where TDep : notnull { throw null; } + public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation, string failureMessage) where TDep : notnull { throw null; } + public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation) where TDep1 : notnull where TDep2 : notnull { throw null; } + public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation, string failureMessage) where TDep1 : notnull where TDep2 : notnull { throw null; } + public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation) where TDep1 : notnull where TDep2 : notnull where TDep3 : notnull { throw null; } + public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation, string failureMessage) where TDep1 : notnull where TDep2 : notnull where TDep3 : notnull { throw null; } + public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation) where TDep1 : notnull where TDep2 : notnull where TDep3 : notnull where TDep4 : notnull { throw null; } + public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation, string failureMessage) where TDep1 : notnull where TDep2 : notnull where TDep3 : notnull where TDep4 : notnull { throw null; } + public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation) where TDep1 : notnull where TDep2 : notnull where TDep3 : notnull where TDep4 : notnull where TDep5 : notnull { throw null; } + public virtual Microsoft.Extensions.Options.OptionsBuilder Validate(System.Func validation, string failureMessage) where TDep1 : notnull where TDep2 : notnull where TDep3 : notnull where TDep4 : notnull where TDep5 : notnull { throw null; } } public partial class OptionsCache<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions> : Microsoft.Extensions.Options.IOptionsMonitorCache where TOptions : class { public OptionsCache() { } public void Clear() { } - public virtual TOptions GetOrAdd(string name, System.Func createOptions) { throw null; } - public virtual bool TryAdd(string name, TOptions options) { throw null; } - public virtual bool TryRemove(string name) { throw null; } + public virtual TOptions GetOrAdd(string? name, System.Func createOptions) { throw null; } + public virtual bool TryAdd(string? name, TOptions options) { throw null; } + public virtual bool TryRemove(string? name) { throw null; } } public partial class OptionsFactory<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions> : Microsoft.Extensions.Options.IOptionsFactory where TOptions : class { @@ -193,7 +193,7 @@ namespace Microsoft.Extensions.Options { public OptionsManager(Microsoft.Extensions.Options.IOptionsFactory factory) { } public TOptions Value { get { throw null; } } - public virtual TOptions Get(string name) { throw null; } + public virtual TOptions Get(string? name) { throw null; } } public static partial class OptionsMonitorExtensions { @@ -204,12 +204,12 @@ namespace Microsoft.Extensions.Options public OptionsMonitor(Microsoft.Extensions.Options.IOptionsFactory factory, System.Collections.Generic.IEnumerable> sources, Microsoft.Extensions.Options.IOptionsMonitorCache cache) { } public TOptions CurrentValue { get { throw null; } } public void Dispose() { } - public virtual TOptions Get(string name) { throw null; } + public virtual TOptions Get(string? name) { throw null; } public System.IDisposable OnChange(System.Action listener) { throw null; } } public partial class OptionsValidationException : System.Exception { - public OptionsValidationException(string optionsName, System.Type optionsType, System.Collections.Generic.IEnumerable failureMessages) { } + public OptionsValidationException(string optionsName, System.Type optionsType, System.Collections.Generic.IEnumerable? failureMessages) { } public System.Collections.Generic.IEnumerable Failures { get { throw null; } } public override string Message { get { throw null; } } public string OptionsName { get { throw null; } } @@ -222,64 +222,64 @@ namespace Microsoft.Extensions.Options } public partial class PostConfigureOptions : Microsoft.Extensions.Options.IPostConfigureOptions where TOptions : class { - public PostConfigureOptions(string name, System.Action action) { } - public System.Action Action { get { throw null; } } - public string Name { get { throw null; } } - public virtual void PostConfigure(string name, TOptions options) { } + public PostConfigureOptions(string? name, System.Action? action) { } + public System.Action? Action { get { throw null; } } + public string? Name { get { throw null; } } + public virtual void PostConfigure(string? name, TOptions options) { } } public partial class PostConfigureOptions : Microsoft.Extensions.Options.IPostConfigureOptions where TOptions : class where TDep : class { - public PostConfigureOptions(string name, TDep dependency, System.Action action) { } - public System.Action Action { get { throw null; } } + public PostConfigureOptions(string? name, TDep dependency, System.Action? action) { } + public System.Action? Action { get { throw null; } } public TDep Dependency { get { throw null; } } - public string Name { get { throw null; } } - public virtual void PostConfigure(string name, TOptions options) { } + public string? Name { get { throw null; } } + public virtual void PostConfigure(string? name, TOptions options) { } public void PostConfigure(TOptions options) { } } public partial class PostConfigureOptions : Microsoft.Extensions.Options.IPostConfigureOptions where TOptions : class where TDep1 : class where TDep2 : class { - public PostConfigureOptions(string name, TDep1 dependency, TDep2 dependency2, System.Action action) { } - public System.Action Action { get { throw null; } } + public PostConfigureOptions(string? name, TDep1 dependency, TDep2 dependency2, System.Action? action) { } + public System.Action? Action { get { throw null; } } public TDep1 Dependency1 { get { throw null; } } public TDep2 Dependency2 { get { throw null; } } - public string Name { get { throw null; } } - public virtual void PostConfigure(string name, TOptions options) { } + public string? Name { get { throw null; } } + public virtual void PostConfigure(string? name, TOptions options) { } public void PostConfigure(TOptions options) { } } public partial class PostConfigureOptions : Microsoft.Extensions.Options.IPostConfigureOptions where TOptions : class where TDep1 : class where TDep2 : class where TDep3 : class { - public PostConfigureOptions(string name, TDep1 dependency, TDep2 dependency2, TDep3 dependency3, System.Action action) { } - public System.Action Action { get { throw null; } } + public PostConfigureOptions(string? name, TDep1 dependency, TDep2 dependency2, TDep3 dependency3, System.Action? action) { } + public System.Action? Action { get { throw null; } } public TDep1 Dependency1 { get { throw null; } } public TDep2 Dependency2 { get { throw null; } } public TDep3 Dependency3 { get { throw null; } } - public string Name { get { throw null; } } - public virtual void PostConfigure(string name, TOptions options) { } + public string? Name { get { throw null; } } + public virtual void PostConfigure(string? name, TOptions options) { } public void PostConfigure(TOptions options) { } } public partial class PostConfigureOptions : Microsoft.Extensions.Options.IPostConfigureOptions where TOptions : class where TDep1 : class where TDep2 : class where TDep3 : class where TDep4 : class { - public PostConfigureOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, System.Action action) { } - public System.Action Action { get { throw null; } } + public PostConfigureOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, System.Action? action) { } + public System.Action? Action { get { throw null; } } public TDep1 Dependency1 { get { throw null; } } public TDep2 Dependency2 { get { throw null; } } public TDep3 Dependency3 { get { throw null; } } public TDep4 Dependency4 { get { throw null; } } - public string Name { get { throw null; } } - public virtual void PostConfigure(string name, TOptions options) { } + public string? Name { get { throw null; } } + public virtual void PostConfigure(string? name, TOptions options) { } public void PostConfigure(TOptions options) { } } public partial class PostConfigureOptions : Microsoft.Extensions.Options.IPostConfigureOptions where TOptions : class where TDep1 : class where TDep2 : class where TDep3 : class where TDep4 : class where TDep5 : class { - public PostConfigureOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, TDep5 dependency5, System.Action action) { } - public System.Action Action { get { throw null; } } + public PostConfigureOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, TDep5 dependency5, System.Action? action) { } + public System.Action? Action { get { throw null; } } public TDep1 Dependency1 { get { throw null; } } public TDep2 Dependency2 { get { throw null; } } public TDep3 Dependency3 { get { throw null; } } public TDep4 Dependency4 { get { throw null; } } public TDep5 Dependency5 { get { throw null; } } - public string Name { get { throw null; } } - public virtual void PostConfigure(string name, TOptions options) { } + public string? Name { get { throw null; } } + public virtual void PostConfigure(string? name, TOptions options) { } public void PostConfigure(TOptions options) { } } public partial class ValidateOptionsResult @@ -287,9 +287,11 @@ namespace Microsoft.Extensions.Options public static readonly Microsoft.Extensions.Options.ValidateOptionsResult Skip; public static readonly Microsoft.Extensions.Options.ValidateOptionsResult Success; public ValidateOptionsResult() { } + [System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(Failures))] + [System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(FailureMessage))] public bool Failed { get { throw null; } protected set { } } - public string FailureMessage { get { throw null; } protected set { } } - public System.Collections.Generic.IEnumerable Failures { get { throw null; } protected set { } } + public string? FailureMessage { get { throw null; } protected set { } } + public System.Collections.Generic.IEnumerable? Failures { get { throw null; } protected set { } } public bool Skipped { get { throw null; } protected set { } } public bool Succeeded { get { throw null; } protected set { } } public static Microsoft.Extensions.Options.ValidateOptionsResult Fail(System.Collections.Generic.IEnumerable failures) { throw null; } @@ -297,65 +299,65 @@ namespace Microsoft.Extensions.Options } public partial class ValidateOptions : Microsoft.Extensions.Options.IValidateOptions where TOptions : class { - public ValidateOptions(string name, System.Func validation, string failureMessage) { } + public ValidateOptions(string? name, System.Func validation, string failureMessage) { } public string FailureMessage { get { throw null; } } - public string Name { get { throw null; } } + public string? Name { get { throw null; } } public System.Func Validation { get { throw null; } } - public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string name, TOptions options) { throw null; } + public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, TOptions options) { throw null; } } public partial class ValidateOptions : Microsoft.Extensions.Options.IValidateOptions where TOptions : class { - public ValidateOptions(string name, TDep dependency, System.Func validation, string failureMessage) { } + public ValidateOptions(string? name, TDep dependency, System.Func validation, string failureMessage) { } public TDep Dependency { get { throw null; } } public string FailureMessage { get { throw null; } } - public string Name { get { throw null; } } + public string? Name { get { throw null; } } public System.Func Validation { get { throw null; } } - public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string name, TOptions options) { throw null; } + public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, TOptions options) { throw null; } } public partial class ValidateOptions : Microsoft.Extensions.Options.IValidateOptions where TOptions : class { - public ValidateOptions(string name, TDep1 dependency1, TDep2 dependency2, System.Func validation, string failureMessage) { } + public ValidateOptions(string? name, TDep1 dependency1, TDep2 dependency2, System.Func validation, string failureMessage) { } public TDep1 Dependency1 { get { throw null; } } public TDep2 Dependency2 { get { throw null; } } public string FailureMessage { get { throw null; } } - public string Name { get { throw null; } } + public string? Name { get { throw null; } } public System.Func Validation { get { throw null; } } - public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string name, TOptions options) { throw null; } + public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, TOptions options) { throw null; } } public partial class ValidateOptions : Microsoft.Extensions.Options.IValidateOptions where TOptions : class { - public ValidateOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, System.Func validation, string failureMessage) { } + public ValidateOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, System.Func validation, string failureMessage) { } public TDep1 Dependency1 { get { throw null; } } public TDep2 Dependency2 { get { throw null; } } public TDep3 Dependency3 { get { throw null; } } public string FailureMessage { get { throw null; } } - public string Name { get { throw null; } } + public string? Name { get { throw null; } } public System.Func Validation { get { throw null; } } - public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string name, TOptions options) { throw null; } + public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, TOptions options) { throw null; } } public partial class ValidateOptions : Microsoft.Extensions.Options.IValidateOptions where TOptions : class { - public ValidateOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, System.Func validation, string failureMessage) { } + public ValidateOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, System.Func validation, string failureMessage) { } public TDep1 Dependency1 { get { throw null; } } public TDep2 Dependency2 { get { throw null; } } public TDep3 Dependency3 { get { throw null; } } public TDep4 Dependency4 { get { throw null; } } public string FailureMessage { get { throw null; } } - public string Name { get { throw null; } } + public string? Name { get { throw null; } } public System.Func Validation { get { throw null; } } - public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string name, TOptions options) { throw null; } + public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, TOptions options) { throw null; } } public partial class ValidateOptions : Microsoft.Extensions.Options.IValidateOptions where TOptions : class { - public ValidateOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, TDep5 dependency5, System.Func validation, string failureMessage) { } + public ValidateOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, TDep5 dependency5, System.Func validation, string failureMessage) { } public TDep1 Dependency1 { get { throw null; } } public TDep2 Dependency2 { get { throw null; } } public TDep3 Dependency3 { get { throw null; } } public TDep4 Dependency4 { get { throw null; } } public TDep5 Dependency5 { get { throw null; } } public string FailureMessage { get { throw null; } } - public string Name { get { throw null; } } + public string? Name { get { throw null; } } public System.Func Validation { get { throw null; } } - public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string name, TOptions options) { throw null; } + public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, TOptions options) { throw null; } } } diff --git a/src/libraries/Microsoft.Extensions.Options/ref/Microsoft.Extensions.Options.csproj b/src/libraries/Microsoft.Extensions.Options/ref/Microsoft.Extensions.Options.csproj index 2d11420..4ba4e7d 100644 --- a/src/libraries/Microsoft.Extensions.Options/ref/Microsoft.Extensions.Options.csproj +++ b/src/libraries/Microsoft.Extensions.Options/ref/Microsoft.Extensions.Options.csproj @@ -1,6 +1,7 @@ $(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.1;netstandard2.0;$(NetFrameworkMinimum) + enable diff --git a/src/libraries/Microsoft.Extensions.Options/src/ConfigureNamedOptions.cs b/src/libraries/Microsoft.Extensions.Options/src/ConfigureNamedOptions.cs index cf4bc8c..a3f9409 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/ConfigureNamedOptions.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/ConfigureNamedOptions.cs @@ -16,7 +16,7 @@ namespace Microsoft.Extensions.Options /// /// The name of the options. /// The action to register. - public ConfigureNamedOptions(string name, Action action) + public ConfigureNamedOptions(string? name, Action? action) { Name = name; Action = action; @@ -25,19 +25,19 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The configuration action. /// - public Action Action { get; } + public Action? Action { get; } /// /// Invokes the registered configure if the matches. /// /// The name of the options instance being configured. /// The options instance to configure. - public virtual void Configure(string name, TOptions options!!) + public virtual void Configure(string? name, TOptions options!!) { // Null name is used to configure all named options. if (Name == null || name == Name) @@ -68,7 +68,7 @@ namespace Microsoft.Extensions.Options /// The name of the options. /// A dependency. /// The action to register. - public ConfigureNamedOptions(string name, TDep dependency, Action action) + public ConfigureNamedOptions(string? name, TDep dependency, Action? action) { Name = name; Action = action; @@ -78,12 +78,12 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The configuration action. /// - public Action Action { get; } + public Action? Action { get; } /// /// The dependency. @@ -95,7 +95,7 @@ namespace Microsoft.Extensions.Options /// /// The name of the options instance being configured. /// The options instance to configure. - public virtual void Configure(string name, TOptions options!!) + public virtual void Configure(string? name, TOptions options!!) { // Null name is used to configure all named options. if (Name == null || name == Name) @@ -129,7 +129,7 @@ namespace Microsoft.Extensions.Options /// A dependency. /// A second dependency. /// The action to register. - public ConfigureNamedOptions(string name, TDep1 dependency, TDep2 dependency2, Action action) + public ConfigureNamedOptions(string? name, TDep1 dependency, TDep2 dependency2, Action? action) { Name = name; Action = action; @@ -140,12 +140,12 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The configuration action. /// - public Action Action { get; } + public Action? Action { get; } /// /// The first dependency. @@ -162,7 +162,7 @@ namespace Microsoft.Extensions.Options /// /// The name of the options instance being configured. /// The options instance to configure. - public virtual void Configure(string name, TOptions options!!) + public virtual void Configure(string? name, TOptions options!!) { // Null name is used to configure all named options. if (Name == null || name == Name) @@ -199,7 +199,7 @@ namespace Microsoft.Extensions.Options /// A second dependency. /// A third dependency. /// The action to register. - public ConfigureNamedOptions(string name, TDep1 dependency, TDep2 dependency2, TDep3 dependency3, Action action) + public ConfigureNamedOptions(string? name, TDep1 dependency, TDep2 dependency2, TDep3 dependency3, Action? action) { Name = name; Action = action; @@ -211,12 +211,12 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The configuration action. /// - public Action Action { get; } + public Action? Action { get; } /// /// The first dependency. @@ -238,7 +238,7 @@ namespace Microsoft.Extensions.Options /// /// The name of the options instance being configured. /// The options instance to configure. - public virtual void Configure(string name, TOptions options!!) + public virtual void Configure(string? name, TOptions options!!) { // Null name is used to configure all named options. if (Name == null || name == Name) @@ -278,7 +278,7 @@ namespace Microsoft.Extensions.Options /// A third dependency. /// A fourth dependency. /// The action to register. - public ConfigureNamedOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, Action action) + public ConfigureNamedOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, Action? action) { Name = name; Action = action; @@ -291,12 +291,12 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The configuration action. /// - public Action Action { get; } + public Action? Action { get; } /// /// The first dependency. @@ -323,7 +323,7 @@ namespace Microsoft.Extensions.Options /// /// The name of the options instance being configured. /// The options instance to configure. - public virtual void Configure(string name, TOptions options!!) + public virtual void Configure(string? name, TOptions options!!) { // Null name is used to configure all named options. if (Name == null || name == Name) @@ -366,7 +366,7 @@ namespace Microsoft.Extensions.Options /// A fourth dependency. /// A fifth dependency. /// The action to register. - public ConfigureNamedOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, TDep5 dependency5, Action action) + public ConfigureNamedOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, TDep5 dependency5, Action? action) { Name = name; Action = action; @@ -380,12 +380,12 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The configuration action. /// - public Action Action { get; } + public Action? Action { get; } /// /// The first dependency. @@ -417,7 +417,7 @@ namespace Microsoft.Extensions.Options /// /// The name of the options instance being configured. /// The options instance to configure. - public virtual void Configure(string name, TOptions options!!) + public virtual void Configure(string? name, TOptions options!!) { // Null name is used to configure all named options. if (Name == null || name == Name) diff --git a/src/libraries/Microsoft.Extensions.Options/src/ConfigureOptions.cs b/src/libraries/Microsoft.Extensions.Options/src/ConfigureOptions.cs index fa9c3b8..556f45b 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/ConfigureOptions.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/ConfigureOptions.cs @@ -15,7 +15,7 @@ namespace Microsoft.Extensions.Options /// Constructor. /// /// The action to register. - public ConfigureOptions(Action action) + public ConfigureOptions(Action? action) { Action = action; } @@ -23,7 +23,7 @@ namespace Microsoft.Extensions.Options /// /// The configuration action. /// - public Action Action { get; } + public Action? Action { get; } /// /// Invokes the registered configure . diff --git a/src/libraries/Microsoft.Extensions.Options/src/IConfigureNamedOptions.cs b/src/libraries/Microsoft.Extensions.Options/src/IConfigureNamedOptions.cs index 7cb70f3..8dfef1e 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/IConfigureNamedOptions.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/IConfigureNamedOptions.cs @@ -14,6 +14,6 @@ namespace Microsoft.Extensions.Options /// /// The name of the options instance being configured. /// The options instance to configure. - void Configure(string name, TOptions options); + void Configure(string? name, TOptions options); } } diff --git a/src/libraries/Microsoft.Extensions.Options/src/IOptionsChangeTokenSource.cs b/src/libraries/Microsoft.Extensions.Options/src/IOptionsChangeTokenSource.cs index dd7ec5b..d290a04 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/IOptionsChangeTokenSource.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/IOptionsChangeTokenSource.cs @@ -20,6 +20,6 @@ namespace Microsoft.Extensions.Options /// /// The name of the option instance being changed. /// - string Name { get; } + string? Name { get; } } } diff --git a/src/libraries/Microsoft.Extensions.Options/src/IOptionsMonitor.cs b/src/libraries/Microsoft.Extensions.Options/src/IOptionsMonitor.cs index 10c51cb..a3696fb 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/IOptionsMonitor.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/IOptionsMonitor.cs @@ -20,13 +20,13 @@ namespace Microsoft.Extensions.Options /// /// Returns a configured instance with the given name. /// - TOptions Get(string name); + TOptions Get(string? name); /// /// Registers a listener to be called whenever a named changes. /// /// The action to be invoked when has changed. /// An which should be disposed to stop listening for changes. - IDisposable OnChange(Action listener); + IDisposable OnChange(Action listener); } } diff --git a/src/libraries/Microsoft.Extensions.Options/src/IOptionsMonitorCache.cs b/src/libraries/Microsoft.Extensions.Options/src/IOptionsMonitorCache.cs index f06062d..ae924ad 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/IOptionsMonitorCache.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/IOptionsMonitorCache.cs @@ -19,7 +19,7 @@ namespace Microsoft.Extensions.Options /// The name of the options instance. /// The func used to create the new instance. /// The options instance. - TOptions GetOrAdd(string name, Func createOptions); + TOptions GetOrAdd(string? name, Func createOptions); /// /// Tries to adds a new option to the cache, will return false if the name already exists. @@ -27,14 +27,14 @@ namespace Microsoft.Extensions.Options /// The name of the options instance. /// The options instance. /// Whether anything was added. - bool TryAdd(string name, TOptions options); + bool TryAdd(string? name, TOptions options); /// /// Try to remove an options instance. /// /// The name of the options instance. /// Whether anything was removed. - bool TryRemove(string name); + bool TryRemove(string? name); /// /// Clears all options instances from the cache. diff --git a/src/libraries/Microsoft.Extensions.Options/src/IOptionsSnapshot.cs b/src/libraries/Microsoft.Extensions.Options/src/IOptionsSnapshot.cs index d29a381..c0afce9 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/IOptionsSnapshot.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/IOptionsSnapshot.cs @@ -16,6 +16,6 @@ namespace Microsoft.Extensions.Options /// /// Returns a configured instance with the given name. /// - TOptions Get(string name); + TOptions Get(string? name); } } diff --git a/src/libraries/Microsoft.Extensions.Options/src/IPostConfigureOptions.cs b/src/libraries/Microsoft.Extensions.Options/src/IPostConfigureOptions.cs index f0f46cb..5b92895 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/IPostConfigureOptions.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/IPostConfigureOptions.cs @@ -15,6 +15,6 @@ namespace Microsoft.Extensions.Options /// /// The name of the options instance being configured. /// The options instance to configured. - void PostConfigure(string name, TOptions options); + void PostConfigure(string? name, TOptions options); } } diff --git a/src/libraries/Microsoft.Extensions.Options/src/IValidateOptions.cs b/src/libraries/Microsoft.Extensions.Options/src/IValidateOptions.cs index 6022b30..cd114ee 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/IValidateOptions.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/IValidateOptions.cs @@ -15,6 +15,6 @@ namespace Microsoft.Extensions.Options /// The name of the options instance being validated. /// The options instance. /// The result. - ValidateOptionsResult Validate(string name, TOptions options); + ValidateOptionsResult Validate(string? name, TOptions options); } } diff --git a/src/libraries/Microsoft.Extensions.Options/src/Microsoft.Extensions.Options.csproj b/src/libraries/Microsoft.Extensions.Options/src/Microsoft.Extensions.Options.csproj index 9ed0d47..f593699 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/Microsoft.Extensions.Options.csproj +++ b/src/libraries/Microsoft.Extensions.Options/src/Microsoft.Extensions.Options.csproj @@ -2,6 +2,7 @@ $(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.1;netstandard2.0;$(NetFrameworkMinimum) + enable true false diff --git a/src/libraries/Microsoft.Extensions.Options/src/OptionsBuilder.cs b/src/libraries/Microsoft.Extensions.Options/src/OptionsBuilder.cs index a1baf74..5819ee0 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/OptionsBuilder.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/OptionsBuilder.cs @@ -29,7 +29,7 @@ namespace Microsoft.Extensions.Options /// /// The for the options being configured. /// The default name of the instance, if null is used. - public OptionsBuilder(IServiceCollection services!!, string name) + public OptionsBuilder(IServiceCollection services!!, string? name) { Services = services; Name = name ?? Options.DefaultName; @@ -310,7 +310,7 @@ namespace Microsoft.Extensions.Options /// The dependency used by the validation function. /// The validation function. /// The current . - public virtual OptionsBuilder Validate(Func validation) + public virtual OptionsBuilder Validate(Func validation) where TDep : notnull => Validate(validation: validation, failureMessage: DefaultValidationFailureMessage); /// @@ -320,7 +320,7 @@ namespace Microsoft.Extensions.Options /// The validation function. /// The failure message to use when validation fails. /// The current . - public virtual OptionsBuilder Validate(Func validation!!, string failureMessage) + public virtual OptionsBuilder Validate(Func validation!!, string failureMessage) where TDep : notnull { Services.AddTransient>(sp => new ValidateOptions(Name, sp.GetRequiredService(), validation, failureMessage)); @@ -335,6 +335,8 @@ namespace Microsoft.Extensions.Options /// The validation function. /// The current . public virtual OptionsBuilder Validate(Func validation) + where TDep1 : notnull + where TDep2 : notnull => Validate(validation: validation, failureMessage: DefaultValidationFailureMessage); /// @@ -346,6 +348,8 @@ namespace Microsoft.Extensions.Options /// The failure message to use when validation fails. /// The current . public virtual OptionsBuilder Validate(Func validation!!, string failureMessage) + where TDep1 : notnull + where TDep2 : notnull { Services.AddTransient>(sp => new ValidateOptions(Name, @@ -365,6 +369,9 @@ namespace Microsoft.Extensions.Options /// The validation function. /// The current . public virtual OptionsBuilder Validate(Func validation) + where TDep1 : notnull + where TDep2 : notnull + where TDep3 : notnull => Validate(validation: validation, failureMessage: DefaultValidationFailureMessage); /// @@ -377,6 +384,9 @@ namespace Microsoft.Extensions.Options /// The failure message to use when validation fails. /// The current . public virtual OptionsBuilder Validate(Func validation!!, string failureMessage) + where TDep1 : notnull + where TDep2 : notnull + where TDep3 : notnull { Services.AddTransient>(sp => new ValidateOptions(Name, @@ -398,6 +408,10 @@ namespace Microsoft.Extensions.Options /// The validation function. /// The current . public virtual OptionsBuilder Validate(Func validation) + where TDep1 : notnull + where TDep2 : notnull + where TDep3 : notnull + where TDep4 : notnull => Validate(validation: validation, failureMessage: DefaultValidationFailureMessage); /// @@ -411,6 +425,10 @@ namespace Microsoft.Extensions.Options /// The failure message to use when validation fails. /// The current . public virtual OptionsBuilder Validate(Func validation!!, string failureMessage) + where TDep1 : notnull + where TDep2 : notnull + where TDep3 : notnull + where TDep4 : notnull { Services.AddTransient>(sp => new ValidateOptions(Name, @@ -434,6 +452,11 @@ namespace Microsoft.Extensions.Options /// The validation function. /// The current . public virtual OptionsBuilder Validate(Func validation) + where TDep1 : notnull + where TDep2 : notnull + where TDep3 : notnull + where TDep4 : notnull + where TDep5 : notnull => Validate(validation: validation, failureMessage: DefaultValidationFailureMessage); /// @@ -448,6 +471,11 @@ namespace Microsoft.Extensions.Options /// The failure message to use when validation fails. /// The current . public virtual OptionsBuilder Validate(Func validation!!, string failureMessage) + where TDep1 : notnull + where TDep2 : notnull + where TDep3 : notnull + where TDep4 : notnull + where TDep5 : notnull { Services.AddTransient>(sp => new ValidateOptions(Name, diff --git a/src/libraries/Microsoft.Extensions.Options/src/OptionsCache.cs b/src/libraries/Microsoft.Extensions.Options/src/OptionsCache.cs index f431291..869fd75 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/OptionsCache.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/OptionsCache.cs @@ -28,10 +28,10 @@ namespace Microsoft.Extensions.Options /// The name of the options instance. /// The func used to create the new instance. /// The options instance. - public virtual TOptions GetOrAdd(string name, Func createOptions!!) + public virtual TOptions GetOrAdd(string? name, Func createOptions!!) { name ??= Options.DefaultName; - Lazy value; + Lazy? value; #if NETSTANDARD2_1 value = _cache.GetOrAdd(name, static (name, createOptions) => new Lazy(createOptions), createOptions); @@ -51,9 +51,9 @@ namespace Microsoft.Extensions.Options /// The name of the options instance. /// The options instance. /// true if the options were retrieved; otherwise, false. - internal bool TryGetValue(string name, out TOptions options) + internal bool TryGetValue(string? name, [MaybeNullWhen(false)] out TOptions options) { - if (_cache.TryGetValue(name ?? Options.DefaultName, out Lazy lazy)) + if (_cache.TryGetValue(name ?? Options.DefaultName, out Lazy? lazy)) { options = lazy.Value; return true; @@ -69,7 +69,7 @@ namespace Microsoft.Extensions.Options /// The name of the options instance. /// The options instance. /// Whether anything was added. - public virtual bool TryAdd(string name, TOptions options!!) + public virtual bool TryAdd(string? name, TOptions options!!) { return _cache.TryAdd(name ?? Options.DefaultName, new Lazy( #if !NETSTANDARD2_1 @@ -83,7 +83,7 @@ namespace Microsoft.Extensions.Options /// /// The name of the options instance. /// Whether anything was removed. - public virtual bool TryRemove(string name) => + public virtual bool TryRemove(string? name) => _cache.TryRemove(name ?? Options.DefaultName, out _); } } diff --git a/src/libraries/Microsoft.Extensions.Options/src/OptionsManager.cs b/src/libraries/Microsoft.Extensions.Options/src/OptionsManager.cs index 83fc0ec..f5a7442 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/OptionsManager.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/OptionsManager.cs @@ -34,11 +34,11 @@ namespace Microsoft.Extensions.Options /// /// Returns a configured instance with the given . /// - public virtual TOptions Get(string name) + public virtual TOptions Get(string? name) { name = name ?? Options.DefaultName; - if (!_cache.TryGetValue(name, out TOptions options)) + if (!_cache.TryGetValue(name, out TOptions? options)) { // Store the options in our instance cache. Avoid closure on fast path by storing state into scoped locals. IOptionsFactory localFactory = _factory; diff --git a/src/libraries/Microsoft.Extensions.Options/src/OptionsMonitor.cs b/src/libraries/Microsoft.Extensions.Options/src/OptionsMonitor.cs index 2b7fbf0..d75bc70 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/OptionsMonitor.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/OptionsMonitor.cs @@ -20,7 +20,7 @@ namespace Microsoft.Extensions.Options private readonly IOptionsMonitorCache _cache; private readonly IOptionsFactory _factory; private readonly List _registrations = new List(); - internal event Action _onChange; + internal event Action? _onChange; /// /// Constructor. @@ -61,7 +61,7 @@ namespace Microsoft.Extensions.Options } } - private void InvokeChanged(string name) + private void InvokeChanged(string? name) { name = name ?? Options.DefaultName; _cache.TryRemove(name); @@ -83,7 +83,7 @@ namespace Microsoft.Extensions.Options /// /// Returns a configured instance with the given . /// - public virtual TOptions Get(string name) + public virtual TOptions Get(string? name) { name = name ?? Options.DefaultName; return _cache.GetOrAdd(name, () => _factory.Create(name)); diff --git a/src/libraries/Microsoft.Extensions.Options/src/OptionsServiceCollectionExtensions.cs b/src/libraries/Microsoft.Extensions.Options/src/OptionsServiceCollectionExtensions.cs index eff6706..73e3c43 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/OptionsServiceCollectionExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/OptionsServiceCollectionExtensions.cs @@ -49,7 +49,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The name of the options instance. /// The action used to configure the options. /// The so that additional calls can be chained. - public static IServiceCollection Configure(this IServiceCollection services!!, string name, Action configureOptions!!) + public static IServiceCollection Configure(this IServiceCollection services!!, string? name, Action configureOptions!!) where TOptions : class { services.AddOptions(); @@ -87,7 +87,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The name of the options instance. /// The action used to configure the options. /// The so that additional calls can be chained. - public static IServiceCollection PostConfigure(this IServiceCollection services!!, string name, Action configureOptions!!) + public static IServiceCollection PostConfigure(this IServiceCollection services!!, string? name, Action configureOptions!!) where TOptions : class { services.AddOptions(); @@ -225,7 +225,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The to add the services to. /// The name of the options instance. /// The so that configure calls can be chained in it. - public static OptionsBuilder AddOptions(this IServiceCollection services!!, string name) + public static OptionsBuilder AddOptions(this IServiceCollection services!!, string? name) where TOptions : class { services.AddOptions(); diff --git a/src/libraries/Microsoft.Extensions.Options/src/OptionsValidationException.cs b/src/libraries/Microsoft.Extensions.Options/src/OptionsValidationException.cs index b20e185..f5b4bcf 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/OptionsValidationException.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/OptionsValidationException.cs @@ -17,7 +17,7 @@ namespace Microsoft.Extensions.Options /// The name of the options instance that failed. /// The options type that failed. /// The validation failure messages. - public OptionsValidationException(string optionsName!!, Type optionsType!!, IEnumerable failureMessages) + public OptionsValidationException(string optionsName!!, Type optionsType!!, IEnumerable? failureMessages) { Failures = failureMessages ?? new List(); OptionsType = optionsType; diff --git a/src/libraries/Microsoft.Extensions.Options/src/OptionsWrapper.cs b/src/libraries/Microsoft.Extensions.Options/src/OptionsWrapper.cs index cdc2958..4de276d 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/OptionsWrapper.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/OptionsWrapper.cs @@ -14,7 +14,7 @@ namespace Microsoft.Extensions.Options where TOptions : class { /// - /// Intializes the wrapper with the options instance to return. + /// Initializes the wrapper with the options instance to return. /// /// The options instance to return. public OptionsWrapper(TOptions options) diff --git a/src/libraries/Microsoft.Extensions.Options/src/PostConfigureOptions.cs b/src/libraries/Microsoft.Extensions.Options/src/PostConfigureOptions.cs index 5049ef1..138220a 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/PostConfigureOptions.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/PostConfigureOptions.cs @@ -16,7 +16,7 @@ namespace Microsoft.Extensions.Options /// /// The name of the options. /// The action to register. - public PostConfigureOptions(string name, Action action) + public PostConfigureOptions(string? name, Action? action) { Name = name; Action = action; @@ -25,19 +25,19 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The initialization action. /// - public Action Action { get; } + public Action? Action { get; } /// /// Invokes the registered initialization if the matches. /// /// The name of the action to invoke. /// The options to use in initialization. - public virtual void PostConfigure(string name, TOptions options!!) + public virtual void PostConfigure(string? name, TOptions options!!) { // Null name is used to initialize all named options. if (Name == null || name == Name) @@ -62,7 +62,7 @@ namespace Microsoft.Extensions.Options /// The name of the options. /// A dependency. /// The action to register. - public PostConfigureOptions(string name, TDep dependency, Action action) + public PostConfigureOptions(string? name, TDep dependency, Action? action) { Name = name; Action = action; @@ -72,12 +72,12 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The configuration action. /// - public Action Action { get; } + public Action? Action { get; } /// /// The dependency. @@ -89,7 +89,7 @@ namespace Microsoft.Extensions.Options /// /// The name of the options instance being configured. /// The options instance to configured. - public virtual void PostConfigure(string name, TOptions options!!) + public virtual void PostConfigure(string? name, TOptions options!!) { // Null name is used to configure all named options. if (Name == null || name == Name) @@ -123,7 +123,7 @@ namespace Microsoft.Extensions.Options /// A dependency. /// A second dependency. /// The action to register. - public PostConfigureOptions(string name, TDep1 dependency, TDep2 dependency2, Action action) + public PostConfigureOptions(string? name, TDep1 dependency, TDep2 dependency2, Action? action) { Name = name; Action = action; @@ -134,12 +134,12 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The configuration action. /// - public Action Action { get; } + public Action? Action { get; } /// /// The first dependency. @@ -156,7 +156,7 @@ namespace Microsoft.Extensions.Options /// /// The name of the options instance being configured. /// The options instance to configured. - public virtual void PostConfigure(string name, TOptions options!!) + public virtual void PostConfigure(string? name, TOptions options!!) { // Null name is used to configure all named options. if (Name == null || name == Name) @@ -193,7 +193,7 @@ namespace Microsoft.Extensions.Options /// A second dependency. /// A third dependency. /// The action to register. - public PostConfigureOptions(string name, TDep1 dependency, TDep2 dependency2, TDep3 dependency3, Action action) + public PostConfigureOptions(string? name, TDep1 dependency, TDep2 dependency2, TDep3 dependency3, Action? action) { Name = name; Action = action; @@ -205,12 +205,12 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The configuration action. /// - public Action Action { get; } + public Action? Action { get; } /// /// The first dependency. @@ -232,7 +232,7 @@ namespace Microsoft.Extensions.Options /// /// The name of the options instance being configured. /// The options instance to configured. - public virtual void PostConfigure(string name, TOptions options!!) + public virtual void PostConfigure(string? name, TOptions options!!) { // Null name is used to configure all named options. if (Name == null || name == Name) @@ -272,7 +272,7 @@ namespace Microsoft.Extensions.Options /// A third dependency. /// A fourth dependency. /// The action to register. - public PostConfigureOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, Action action) + public PostConfigureOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, Action? action) { Name = name; Action = action; @@ -285,12 +285,12 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The configuration action. /// - public Action Action { get; } + public Action? Action { get; } /// /// The first dependency. @@ -317,7 +317,7 @@ namespace Microsoft.Extensions.Options /// /// The name of the options instance being configured. /// The options instance to configured. - public virtual void PostConfigure(string name, TOptions options!!) + public virtual void PostConfigure(string? name, TOptions options!!) { // Null name is used to configure all named options. if (Name == null || name == Name) @@ -360,7 +360,7 @@ namespace Microsoft.Extensions.Options /// A fourth dependency. /// A fifth dependency. /// The action to register. - public PostConfigureOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, TDep5 dependency5, Action action) + public PostConfigureOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, TDep5 dependency5, Action? action) { Name = name; Action = action; @@ -374,12 +374,12 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The configuration action. /// - public Action Action { get; } + public Action? Action { get; } /// /// The first dependency. @@ -411,7 +411,7 @@ namespace Microsoft.Extensions.Options /// /// The name of the options instance being configured. /// The options instance to configured. - public virtual void PostConfigure(string name, TOptions options!!) + public virtual void PostConfigure(string? name, TOptions options!!) { // Null name is used to configure all named options. if (Name == null || name == Name) diff --git a/src/libraries/Microsoft.Extensions.Options/src/UnnamedOptionsManager.cs b/src/libraries/Microsoft.Extensions.Options/src/UnnamedOptionsManager.cs index 93dafb7..27f6d6e 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/UnnamedOptionsManager.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/UnnamedOptionsManager.cs @@ -11,8 +11,8 @@ namespace Microsoft.Extensions.Options where TOptions : class { private readonly IOptionsFactory _factory; - private volatile object _syncObj; - private volatile TOptions _value; + private volatile object? _syncObj; + private volatile TOptions? _value; public UnnamedOptionsManager(IOptionsFactory factory) => _factory = factory; diff --git a/src/libraries/Microsoft.Extensions.Options/src/ValidateOptions.cs b/src/libraries/Microsoft.Extensions.Options/src/ValidateOptions.cs index b70b783..de083ed 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/ValidateOptions.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/ValidateOptions.cs @@ -17,7 +17,7 @@ namespace Microsoft.Extensions.Options /// Options name. /// Validation function. /// Validation failure message. - public ValidateOptions(string name, Func validation, string failureMessage) + public ValidateOptions(string? name, Func validation!!, string failureMessage) { Name = name; Validation = validation; @@ -27,7 +27,7 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The validation function. @@ -45,12 +45,12 @@ namespace Microsoft.Extensions.Options /// The name of the options instance being validated. /// The options instance. /// The result. - public ValidateOptionsResult Validate(string name, TOptions options) + public ValidateOptionsResult Validate(string? name, TOptions options) { // null name is used to configure all named options if (Name == null || name == Name) { - if ((Validation?.Invoke(options)).Value) + if (Validation.Invoke(options)) { return ValidateOptionsResult.Success; } @@ -65,7 +65,7 @@ namespace Microsoft.Extensions.Options /// /// Implementation of /// - /// The options type to validate. + /// The options type to validate. /// Dependency type. public class ValidateOptions : IValidateOptions where TOptions : class { @@ -76,7 +76,7 @@ namespace Microsoft.Extensions.Options /// The dependency. /// Validation function. /// Validation failure message. - public ValidateOptions(string name, TDep dependency, Func validation, string failureMessage) + public ValidateOptions(string? name, TDep dependency, Func validation!!, string failureMessage) { Name = name; Validation = validation; @@ -87,7 +87,7 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The validation function. @@ -110,12 +110,12 @@ namespace Microsoft.Extensions.Options /// The name of the options instance being validated. /// The options instance. /// The result. - public ValidateOptionsResult Validate(string name, TOptions options) + public ValidateOptionsResult Validate(string? name, TOptions options) { // null name is used to configure all named options if (Name == null || name == Name) { - if ((Validation?.Invoke(options, Dependency)).Value) + if (Validation.Invoke(options, Dependency)) { return ValidateOptionsResult.Success; } @@ -130,7 +130,7 @@ namespace Microsoft.Extensions.Options /// /// Implementation of /// - /// The options type to validate. + /// The options type to validate. /// First dependency type. /// Second dependency type. public class ValidateOptions : IValidateOptions where TOptions : class @@ -143,7 +143,7 @@ namespace Microsoft.Extensions.Options /// The second dependency. /// Validation function. /// Validation failure message. - public ValidateOptions(string name, TDep1 dependency1, TDep2 dependency2, Func validation, string failureMessage) + public ValidateOptions(string? name, TDep1 dependency1, TDep2 dependency2, Func validation!!, string failureMessage) { Name = name; Validation = validation; @@ -155,7 +155,7 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The validation function. @@ -183,12 +183,12 @@ namespace Microsoft.Extensions.Options /// The name of the options instance being validated. /// The options instance. /// The result. - public ValidateOptionsResult Validate(string name, TOptions options) + public ValidateOptionsResult Validate(string? name, TOptions options) { // null name is used to configure all named options if (Name == null || name == Name) { - if ((Validation?.Invoke(options, Dependency1, Dependency2)).Value) + if (Validation.Invoke(options, Dependency1, Dependency2)) { return ValidateOptionsResult.Success; } @@ -203,7 +203,7 @@ namespace Microsoft.Extensions.Options /// /// Implementation of /// - /// The options type to validate. + /// The options type to validate. /// First dependency type. /// Second dependency type. /// Third dependency type. @@ -218,7 +218,7 @@ namespace Microsoft.Extensions.Options /// The third dependency. /// Validation function. /// Validation failure message. - public ValidateOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, Func validation, string failureMessage) + public ValidateOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, Func validation!!, string failureMessage) { Name = name; Validation = validation; @@ -231,7 +231,7 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The validation function. @@ -264,12 +264,12 @@ namespace Microsoft.Extensions.Options /// The name of the options instance being validated. /// The options instance. /// The result. - public ValidateOptionsResult Validate(string name, TOptions options) + public ValidateOptionsResult Validate(string? name, TOptions options) { // null name is used to configure all named options if (Name == null || name == Name) { - if ((Validation?.Invoke(options, Dependency1, Dependency2, Dependency3)).Value) + if (Validation.Invoke(options, Dependency1, Dependency2, Dependency3)) { return ValidateOptionsResult.Success; } @@ -284,7 +284,7 @@ namespace Microsoft.Extensions.Options /// /// Implementation of /// - /// The options type to validate. + /// The options type to validate. /// First dependency type. /// Second dependency type. /// Third dependency type. @@ -301,7 +301,7 @@ namespace Microsoft.Extensions.Options /// The fourth dependency. /// Validation function. /// Validation failure message. - public ValidateOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, Func validation, string failureMessage) + public ValidateOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, Func validation!!, string failureMessage) { Name = name; Validation = validation; @@ -315,7 +315,7 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The validation function. @@ -353,12 +353,12 @@ namespace Microsoft.Extensions.Options /// The name of the options instance being validated. /// The options instance. /// The result. - public ValidateOptionsResult Validate(string name, TOptions options) + public ValidateOptionsResult Validate(string? name, TOptions options) { // null name is used to configure all named options if (Name == null || name == Name) { - if ((Validation?.Invoke(options, Dependency1, Dependency2, Dependency3, Dependency4)).Value) + if (Validation.Invoke(options, Dependency1, Dependency2, Dependency3, Dependency4)) { return ValidateOptionsResult.Success; } @@ -373,7 +373,7 @@ namespace Microsoft.Extensions.Options /// /// Implementation of /// - /// The options type to validate. + /// The options type to validate. /// First dependency type. /// Second dependency type. /// Third dependency type. @@ -392,7 +392,7 @@ namespace Microsoft.Extensions.Options /// The fifth dependency. /// Validation function. /// Validation failure message. - public ValidateOptions(string name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, TDep5 dependency5, Func validation, string failureMessage) + public ValidateOptions(string? name, TDep1 dependency1, TDep2 dependency2, TDep3 dependency3, TDep4 dependency4, TDep5 dependency5, Func validation!!, string failureMessage) { Name = name; Validation = validation; @@ -407,7 +407,7 @@ namespace Microsoft.Extensions.Options /// /// The options name. /// - public string Name { get; } + public string? Name { get; } /// /// The validation function. @@ -450,12 +450,12 @@ namespace Microsoft.Extensions.Options /// The name of the options instance being validated. /// The options instance. /// The result. - public ValidateOptionsResult Validate(string name, TOptions options) + public ValidateOptionsResult Validate(string? name, TOptions options) { // null name is used to configure all named options if (Name == null || name == Name) { - if ((Validation?.Invoke(options, Dependency1, Dependency2, Dependency3, Dependency4, Dependency5)).Value) + if (Validation.Invoke(options, Dependency1, Dependency2, Dependency3, Dependency4, Dependency5)) { return ValidateOptionsResult.Success; } diff --git a/src/libraries/Microsoft.Extensions.Options/src/ValidateOptionsResult.cs b/src/libraries/Microsoft.Extensions.Options/src/ValidateOptionsResult.cs index d4c769c..7630208 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/ValidateOptionsResult.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/ValidateOptionsResult.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace Microsoft.Extensions.Options { @@ -34,17 +35,19 @@ namespace Microsoft.Extensions.Options /// /// True if validation failed. /// + [MemberNotNullWhen(true, nameof(Failures))] + [MemberNotNullWhen(true, nameof(FailureMessage))] public bool Failed { get; protected set; } /// /// Used to describe why validation failed. /// - public string FailureMessage { get; protected set; } + public string? FailureMessage { get; protected set; } /// /// Full list of failures (can be multiple). /// - public IEnumerable Failures { get; protected set; } + public IEnumerable? Failures { get; protected set; } /// /// Returns a failure result. diff --git a/src/libraries/Microsoft.Extensions.Options/tests/Microsoft.Extensions.Options.Tests/OptionsValidationTests.cs b/src/libraries/Microsoft.Extensions.Options/tests/Microsoft.Extensions.Options.Tests/OptionsValidationTests.cs index 7b94975..8866038 100644 --- a/src/libraries/Microsoft.Extensions.Options/tests/Microsoft.Extensions.Options.Tests/OptionsValidationTests.cs +++ b/src/libraries/Microsoft.Extensions.Options/tests/Microsoft.Extensions.Options.Tests/OptionsValidationTests.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; using Xunit; @@ -74,5 +75,19 @@ namespace Microsoft.Extensions.Options.Tests } } + [Fact] + public void ValidationCannotBeNull() + { + string validName = "Name"; + string validFailureMessage = "Something's wrong"; + object validDependency = new(); + + Assert.Throws(() => new ValidateOptions(validName, null, validFailureMessage)); + Assert.Throws(() => new ValidateOptions(validName, validDependency, null, validFailureMessage)); + Assert.Throws(() => new ValidateOptions(validName, validDependency, validDependency, null, validFailureMessage)); + Assert.Throws(() => new ValidateOptions(validName, validDependency, validDependency, validDependency, null, validFailureMessage)); + Assert.Throws(() => new ValidateOptions(validName, validDependency, validDependency, validDependency, validDependency, null, validFailureMessage)); + Assert.Throws(() => new ValidateOptions(validName, validDependency, validDependency, validDependency, validDependency, validDependency, null, validFailureMessage)); + } } } -- 2.7.4