Skip to content

Commit 3c5fee9

Browse files
authored
[Group 3] Enable nullable annotations for Microsoft.Extensions.Options.DataAnnotations (#65202)
1 parent 6d8cc6f commit 3c5fee9

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/libraries/Microsoft.Extensions.Options.DataAnnotations/ref/Microsoft.Extensions.Options.DataAnnotations.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ namespace Microsoft.Extensions.Options
1717
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
1818
{
1919
[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.")]
20-
public DataAnnotationValidateOptions(string name) { }
21-
public string Name { get { throw null; } }
22-
public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string name, TOptions options) { throw null; }
20+
public DataAnnotationValidateOptions(string? name) { }
21+
public string? Name { get { throw null; } }
22+
public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, TOptions options) { throw null; }
2323
}
2424
}

src/libraries/Microsoft.Extensions.Options.DataAnnotations/ref/Microsoft.Extensions.Options.DataAnnotations.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.1;netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
4+
<Nullable>enable</Nullable>
45
</PropertyGroup>
56
<ItemGroup>
67
<Compile Include="Microsoft.Extensions.Options.DataAnnotations.cs" />

src/libraries/Microsoft.Extensions.Options.DataAnnotations/src/DataAnnotationValidateOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public class DataAnnotationValidateOptions<[DynamicallyAccessedMembers(Dynamical
2121
/// <param name="name">The name of the option.</param>
2222
[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 " +
2323
"statically analyzed so its members may be trimmed.")]
24-
public DataAnnotationValidateOptions(string name)
24+
public DataAnnotationValidateOptions(string? name)
2525
{
2626
Name = name;
2727
}
2828

2929
/// <summary>
3030
/// The options name.
3131
/// </summary>
32-
public string Name { get; }
32+
public string? Name { get; }
3333

3434
/// <summary>
3535
/// Validates a specific named options instance (or all when <paramref name="name"/> is null).
@@ -39,7 +39,7 @@ public DataAnnotationValidateOptions(string name)
3939
/// <returns>The <see cref="ValidateOptionsResult"/> result.</returns>
4040
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
4141
Justification = "Suppressing the warnings on this method since the constructor of the type is annotated as RequiresUnreferencedCode.")]
42-
public ValidateOptionsResult Validate(string name, TOptions options)
42+
public ValidateOptionsResult Validate(string? name, TOptions options)
4343
{
4444
// Null name is used to configure all named options.
4545
if (Name != null && Name != name)

src/libraries/Microsoft.Extensions.Options.DataAnnotations/src/Microsoft.Extensions.Options.DataAnnotations.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

0 commit comments

Comments
 (0)