Skip to content

Commit 39ddeea

Browse files
committed
Add nullable annotations to Identity.Extensions
1 parent 4310f2c commit 39ddeea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+208
-190
lines changed

src/Identity/EntityFrameworkCore/src/IdentityDbContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ protected IdentityDbContext() { }
9898
/// <summary>
9999
/// Gets or sets the <see cref="DbSet{TEntity}"/> of User roles.
100100
/// </summary>
101-
public virtual DbSet<TUserRole> UserRoles { get; set; }
101+
public virtual DbSet<TUserRole> UserRoles { get; set; } = default!;
102102

103103
/// <summary>
104104
/// Gets or sets the <see cref="DbSet{TEntity}"/> of roles.
105105
/// </summary>
106-
public virtual DbSet<TRole> Roles { get; set; }
106+
public virtual DbSet<TRole> Roles { get; set; } = default!;
107107

108108
/// <summary>
109109
/// Gets or sets the <see cref="DbSet{TEntity}"/> of role claims.
110110
/// </summary>
111-
public virtual DbSet<TRoleClaim> RoleClaims { get; set; }
111+
public virtual DbSet<TRoleClaim> RoleClaims { get; set; } = default!;
112112

113113
/// <summary>
114114
/// Configures the schema needed for the identity framework.

src/Identity/EntityFrameworkCore/src/IdentityEntityFrameworkBuilderExtensions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static IdentityBuilder AddEntityFrameworkStores<TContext>(this IdentityBu
2626
return builder;
2727
}
2828

29-
private static void AddStores(IServiceCollection services, Type userType, Type roleType, Type contextType)
29+
private static void AddStores(IServiceCollection services, Type userType, Type? roleType, Type contextType)
3030
{
3131
var identityUserType = FindGenericBaseType(userType, typeof(IdentityUser<>));
3232
if (identityUserType == null)
@@ -89,12 +89,11 @@ private static void AddStores(IServiceCollection services, Type userType, Type r
8989
}
9090
services.TryAddScoped(typeof(IUserStore<>).MakeGenericType(userType), userStoreType);
9191
}
92-
9392
}
9493

95-
private static Type FindGenericBaseType(Type currentType, Type genericBaseType)
94+
private static Type? FindGenericBaseType(Type currentType, Type genericBaseType)
9695
{
97-
var type = currentType;
96+
Type? type = currentType;
9897
while (type != null)
9998
{
10099
var genericType = type.IsGenericType ? type.GetGenericTypeDefinition() : null;

src/Identity/EntityFrameworkCore/src/IdentityUserContext.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,24 @@ protected IdentityUserContext() { }
7878
/// <summary>
7979
/// Gets or sets the <see cref="DbSet{TEntity}"/> of Users.
8080
/// </summary>
81-
public virtual DbSet<TUser> Users { get; set; }
81+
public virtual DbSet<TUser> Users { get; set; } = default!;
8282

8383
/// <summary>
8484
/// Gets or sets the <see cref="DbSet{TEntity}"/> of User claims.
8585
/// </summary>
86-
public virtual DbSet<TUserClaim> UserClaims { get; set; }
86+
public virtual DbSet<TUserClaim> UserClaims { get; set; } = default!;
8787

8888
/// <summary>
8989
/// Gets or sets the <see cref="DbSet{TEntity}"/> of User logins.
9090
/// </summary>
91-
public virtual DbSet<TUserLogin> UserLogins { get; set; }
91+
public virtual DbSet<TUserLogin> UserLogins { get; set; } = default!;
9292

9393
/// <summary>
9494
/// Gets or sets the <see cref="DbSet{TEntity}"/> of User tokens.
9595
/// </summary>
96-
public virtual DbSet<TUserToken> UserTokens { get; set; }
96+
public virtual DbSet<TUserToken> UserTokens { get; set; } = default!;
9797

98-
private StoreOptions GetStoreOptions() => this.GetService<IDbContextOptions>()
98+
private StoreOptions? GetStoreOptions() => this.GetService<IDbContextOptions>()
9999
.Extensions.OfType<CoreOptionsExtension>()
100100
.FirstOrDefault()?.ApplicationServiceProvider
101101
?.GetService<IOptions<IdentityOptions>>()
@@ -118,7 +118,7 @@ protected override void OnModelCreating(ModelBuilder builder)
118118
var storeOptions = GetStoreOptions();
119119
var maxKeyLength = storeOptions?.MaxLengthForKeys ?? 0;
120120
var encryptPersonalData = storeOptions?.ProtectPersonalData ?? false;
121-
PersonalDataConverter converter = null;
121+
PersonalDataConverter? converter = null;
122122

123123
builder.Entity<TUser>(b =>
124124
{

src/Identity/EntityFrameworkCore/src/Microsoft.AspNetCore.Identity.EntityFrameworkCore.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
<PackageTags>aspnetcore;entityframeworkcore;identity;membership</PackageTags>
8-
<Nullable>disable</Nullable>
8+
<NoWarn>$(NoWarn);RS0036</NoWarn>
9+
910
</PropertyGroup>
1011

1112
<ItemGroup>

src/Identity/EntityFrameworkCore/src/RoleStore.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class RoleStore<TRole> : RoleStore<TRole, DbContext, string>
2020
/// </summary>
2121
/// <param name="context">The <see cref="DbContext"/>.</param>
2222
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
23-
public RoleStore(DbContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
23+
public RoleStore(DbContext context, IdentityErrorDescriber? describer = null) : base(context, describer) { }
2424
}
2525

2626
/// <summary>
@@ -37,7 +37,7 @@ public class RoleStore<TRole, TContext> : RoleStore<TRole, TContext, string>
3737
/// </summary>
3838
/// <param name="context">The <see cref="DbContext"/>.</param>
3939
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
40-
public RoleStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
40+
public RoleStore(TContext context, IdentityErrorDescriber? describer = null) : base(context, describer) { }
4141
}
4242

4343
/// <summary>
@@ -58,7 +58,7 @@ public class RoleStore<TRole, TContext, TKey> : RoleStore<TRole, TContext, TKey,
5858
/// </summary>
5959
/// <param name="context">The <see cref="DbContext"/>.</param>
6060
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
61-
public RoleStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
61+
public RoleStore(TContext context, IdentityErrorDescriber? describer = null) : base(context, describer) { }
6262
}
6363

6464
/// <summary>
@@ -83,7 +83,7 @@ public class RoleStore<TRole, TContext, TKey, TUserRole, TRoleClaim> :
8383
/// </summary>
8484
/// <param name="context">The <see cref="DbContext"/>.</param>
8585
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
86-
public RoleStore(TContext context, IdentityErrorDescriber describer = null)
86+
public RoleStore(TContext context, IdentityErrorDescriber? describer = null)
8787
{
8888
if (context == null)
8989
{
@@ -211,7 +211,7 @@ protected virtual async Task SaveChanges(CancellationToken cancellationToken)
211211
{
212212
throw new ArgumentNullException(nameof(role));
213213
}
214-
return Task.FromResult(ConvertIdToString(role.Id));
214+
return Task.FromResult(ConvertIdToString(role.Id)!);
215215
}
216216

217217
/// <summary>
@@ -255,21 +255,21 @@ protected virtual async Task SaveChanges(CancellationToken cancellationToken)
255255
/// </summary>
256256
/// <param name="id">The id to convert.</param>
257257
/// <returns>An instance of <typeparamref name="TKey"/> representing the provided <paramref name="id"/>.</returns>
258-
public virtual TKey ConvertIdFromString(string id)
258+
public virtual TKey? ConvertIdFromString(string id)
259259
{
260260
if (id == null)
261261
{
262262
return default(TKey);
263263
}
264-
return (TKey)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFromInvariantString(id);
264+
return (TKey?)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFromInvariantString(id);
265265
}
266266

267267
/// <summary>
268268
/// Converts the provided <paramref name="id"/> to its string representation.
269269
/// </summary>
270270
/// <param name="id">The id to convert.</param>
271271
/// <returns>An <see cref="string"/> representation of the provided <paramref name="id"/>.</returns>
272-
public virtual string ConvertIdToString(TKey id)
272+
public virtual string? ConvertIdToString(TKey id)
273273
{
274274
if (id.Equals(default(TKey)))
275275
{
@@ -284,7 +284,7 @@ public virtual string ConvertIdToString(TKey id)
284284
/// <param name="id">The role ID to look for.</param>
285285
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
286286
/// <returns>A <see cref="Task{TResult}"/> that result of the look up.</returns>
287-
public virtual Task<TRole> FindByIdAsync(string id, CancellationToken cancellationToken = default(CancellationToken))
287+
public virtual Task<TRole?> FindByIdAsync(string id, CancellationToken cancellationToken = default(CancellationToken))
288288
{
289289
cancellationToken.ThrowIfCancellationRequested();
290290
ThrowIfDisposed();
@@ -298,7 +298,7 @@ public virtual string ConvertIdToString(TKey id)
298298
/// <param name="normalizedName">The normalized role name to look for.</param>
299299
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
300300
/// <returns>A <see cref="Task{TResult}"/> that result of the look up.</returns>
301-
public virtual Task<TRole> FindByNameAsync(string normalizedName, CancellationToken cancellationToken = default(CancellationToken))
301+
public virtual Task<TRole?> FindByNameAsync(string normalizedName, CancellationToken cancellationToken = default(CancellationToken))
302302
{
303303
cancellationToken.ThrowIfCancellationRequested();
304304
ThrowIfDisposed();

src/Identity/EntityFrameworkCore/src/UserOnlyStore.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore;
1818
/// </summary>
1919
/// <param name="context">The <see cref="DbContext"/>.</param>
2020
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
21-
public UserOnlyStore(DbContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
21+
public UserOnlyStore(DbContext context, IdentityErrorDescriber? describer = null) : base(context, describer) { }
2222
}
2323

2424
/// <summary>
@@ -35,7 +35,7 @@ public class UserOnlyStore<TUser, TContext> : UserOnlyStore<TUser, TContext, str
3535
/// </summary>
3636
/// <param name="context">The <see cref="DbContext"/>.</param>
3737
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
38-
public UserOnlyStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
38+
public UserOnlyStore(TContext context, IdentityErrorDescriber? describer = null) : base(context, describer) { }
3939
}
4040

4141
/// <summary>
@@ -54,7 +54,7 @@ public class UserOnlyStore<TUser, TContext, TKey> : UserOnlyStore<TUser, TContex
5454
/// </summary>
5555
/// <param name="context">The <see cref="DbContext"/>.</param>
5656
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
57-
public UserOnlyStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
57+
public UserOnlyStore(TContext context, IdentityErrorDescriber? describer = null) : base(context, describer) { }
5858
}
5959

6060
/// <summary>
@@ -93,7 +93,7 @@ public class UserOnlyStore<TUser, TContext, TKey, TUserClaim, TUserLogin, TUserT
9393
/// </summary>
9494
/// <param name="context">The context used to access the store.</param>
9595
/// <param name="describer">The <see cref="IdentityErrorDescriber"/> used to describe store errors.</param>
96-
public UserOnlyStore(TContext context, IdentityErrorDescriber describer = null) : base(describer ?? new IdentityErrorDescriber())
96+
public UserOnlyStore(TContext context, IdentityErrorDescriber? describer = null) : base(describer ?? new IdentityErrorDescriber())
9797
{
9898
if (context == null)
9999
{
@@ -226,12 +226,12 @@ protected Task SaveChanges(CancellationToken cancellationToken)
226226
/// <returns>
227227
/// The <see cref="Task"/> that represents the asynchronous operation, containing the user matching the specified <paramref name="userId"/> if it exists.
228228
/// </returns>
229-
public override Task<TUser> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken))
229+
public override Task<TUser?> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken))
230230
{
231231
cancellationToken.ThrowIfCancellationRequested();
232232
ThrowIfDisposed();
233233
var id = ConvertIdFromString(userId);
234-
return UsersSet.FindAsync(new object[] { id }, cancellationToken).AsTask();
234+
return UsersSet.FindAsync(new object?[] { id }, cancellationToken).AsTask();
235235
}
236236

237237
/// <summary>
@@ -242,7 +242,7 @@ protected Task SaveChanges(CancellationToken cancellationToken)
242242
/// <returns>
243243
/// The <see cref="Task"/> that represents the asynchronous operation, containing the user matching the specified <paramref name="normalizedUserName"/> if it exists.
244244
/// </returns>
245-
public override Task<TUser> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken = default(CancellationToken))
245+
public override Task<TUser?> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken = default(CancellationToken))
246246
{
247247
cancellationToken.ThrowIfCancellationRequested();
248248
ThrowIfDisposed();
@@ -264,7 +264,7 @@ public override IQueryable<TUser> Users
264264
/// <param name="userId">The user's id.</param>
265265
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
266266
/// <returns>The user if it exists.</returns>
267-
protected override Task<TUser> FindUserAsync(TKey userId, CancellationToken cancellationToken)
267+
protected override Task<TUser?> FindUserAsync(TKey userId, CancellationToken cancellationToken)
268268
{
269269
return Users.SingleOrDefaultAsync(u => u.Id.Equals(userId), cancellationToken);
270270
}
@@ -277,7 +277,7 @@ protected override Task<TUser> FindUserAsync(TKey userId, CancellationToken canc
277277
/// <param name="providerKey">The key provided by the <paramref name="loginProvider"/> to identify a user.</param>
278278
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
279279
/// <returns>The user login if it exists.</returns>
280-
protected override Task<TUserLogin> FindUserLoginAsync(TKey userId, string loginProvider, string providerKey, CancellationToken cancellationToken)
280+
protected override Task<TUserLogin?> FindUserLoginAsync(TKey userId, string loginProvider, string providerKey, CancellationToken cancellationToken)
281281
{
282282
return UserLogins.SingleOrDefaultAsync(userLogin => userLogin.UserId.Equals(userId) && userLogin.LoginProvider == loginProvider && userLogin.ProviderKey == providerKey, cancellationToken);
283283
}
@@ -289,7 +289,7 @@ protected override Task<TUserLogin> FindUserLoginAsync(TKey userId, string login
289289
/// <param name="providerKey">The key provided by the <paramref name="loginProvider"/> to identify a user.</param>
290290
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
291291
/// <returns>The user login if it exists.</returns>
292-
protected override Task<TUserLogin> FindUserLoginAsync(string loginProvider, string providerKey, CancellationToken cancellationToken)
292+
protected override Task<TUserLogin?> FindUserLoginAsync(string loginProvider, string providerKey, CancellationToken cancellationToken)
293293
{
294294
return UserLogins.SingleOrDefaultAsync(userLogin => userLogin.LoginProvider == loginProvider && userLogin.ProviderKey == providerKey, cancellationToken);
295295
}
@@ -474,7 +474,7 @@ public override async Task RemoveLoginAsync(TUser user, string loginProvider, st
474474
/// <returns>
475475
/// The <see cref="Task"/> for the asynchronous operation, containing the user, if any which matched the specified login provider and key.
476476
/// </returns>
477-
public override async Task<TUser> FindByLoginAsync(string loginProvider, string providerKey,
477+
public override async Task<TUser?> FindByLoginAsync(string loginProvider, string providerKey,
478478
CancellationToken cancellationToken = default(CancellationToken))
479479
{
480480
cancellationToken.ThrowIfCancellationRequested();
@@ -495,7 +495,7 @@ public override async Task<TUser> FindByLoginAsync(string loginProvider, string
495495
/// <returns>
496496
/// The task object containing the results of the asynchronous lookup operation, the user if any associated with the specified normalized email address.
497497
/// </returns>
498-
public override Task<TUser> FindByEmailAsync(string normalizedEmail, CancellationToken cancellationToken = default(CancellationToken))
498+
public override Task<TUser?> FindByEmailAsync(string normalizedEmail, CancellationToken cancellationToken = default(CancellationToken))
499499
{
500500
cancellationToken.ThrowIfCancellationRequested();
501501
ThrowIfDisposed();
@@ -537,7 +537,7 @@ join user in Users on userclaims.UserId equals user.Id
537537
/// <param name="name">The name of the token.</param>
538538
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
539539
/// <returns>The user token if it exists.</returns>
540-
protected override Task<TUserToken> FindTokenAsync(TUser user, string loginProvider, string name, CancellationToken cancellationToken)
540+
protected override Task<TUserToken?> FindTokenAsync(TUser user, string loginProvider, string name, CancellationToken cancellationToken)
541541
=> UserTokens.FindAsync(new object[] { user.Id, loginProvider, name }, cancellationToken).AsTask();
542542

543543
/// <summary>

0 commit comments

Comments
 (0)