Skip to content

Commit

Permalink
[Group 3] Enable nullable annotations for Microsoft.Extensions.Option…
Browse files Browse the repository at this point in the history
…s.DataAnnotations (dotnet#65202)
  • Loading branch information
maxkoshevoi authored Feb 11, 2022
1 parent 6d8cc6f commit 3c5fee9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace Microsoft.Extensions.Options
public partial class DataAnnotationValidateOptions<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicProperties)] TOptions> : Microsoft.Extensions.Options.IValidateOptions<TOptions> where TOptions : class
{
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The implementation of Validate method on this type will walk through all properties of the passed in options object, and its type cannot be statically analyzed so its members may be trimmed.")]
public DataAnnotationValidateOptions(string name) { }
public string Name { get { throw null; } }
public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string name, TOptions options) { throw null; }
public DataAnnotationValidateOptions(string? name) { }
public string? Name { get { throw null; } }
public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, TOptions options) { throw null; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.1;netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="Microsoft.Extensions.Options.DataAnnotations.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public class DataAnnotationValidateOptions<[DynamicallyAccessedMembers(Dynamical
/// <param name="name">The name of the option.</param>
[RequiresUnreferencedCode("The implementation of Validate method on this type will walk through all properties of the passed in options object, and its type cannot be " +
"statically analyzed so its members may be trimmed.")]
public DataAnnotationValidateOptions(string name)
public DataAnnotationValidateOptions(string? name)
{
Name = name;
}

/// <summary>
/// The options name.
/// </summary>
public string Name { get; }
public string? Name { get; }

/// <summary>
/// Validates a specific named options instance (or all when <paramref name="name"/> is null).
Expand All @@ -39,7 +39,7 @@ public DataAnnotationValidateOptions(string name)
/// <returns>The <see cref="ValidateOptionsResult"/> result.</returns>
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "Suppressing the warnings on this method since the constructor of the type is annotated as RequiresUnreferencedCode.")]
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.1;netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>enable</Nullable>
<EnableDefaultItems>true</EnableDefaultItems>
<!-- Use targeting pack references instead of granular ones in the project file. -->
<DisableImplicitAssemblyReferences>false</DisableImplicitAssemblyReferences>
Expand Down

0 comments on commit 3c5fee9

Please sign in to comment.