diff --git a/src/AspNetCore/AspNetCore/src/Authorization/ServiceCollectionExtensions.cs b/src/AspNetCore/AspNetCore/src/Authorization/ServiceCollectionExtensions.cs index 0cfea43..6dfe9aa 100644 --- a/src/AspNetCore/AspNetCore/src/Authorization/ServiceCollectionExtensions.cs +++ b/src/AspNetCore/AspNetCore/src/Authorization/ServiceCollectionExtensions.cs @@ -16,8 +16,7 @@ public static class ServiceCollectionExtensions /// public static void AddAjaxServices(this IServiceCollection services) { - if (services == null) - throw new ArgumentNullException(nameof(services)); + ArgumentNullException.ThrowIfNull(services); // Register the 401/403 handler services.AddTransient(); diff --git a/src/AspNetCore/Authentication/Authentication/src/InMemoryUserSessionStore.cs b/src/AspNetCore/Authentication/Authentication/src/InMemoryUserSessionStore.cs index 34f9d19..3a18dc1 100644 --- a/src/AspNetCore/Authentication/Authentication/src/InMemoryUserSessionStore.cs +++ b/src/AspNetCore/Authentication/Authentication/src/InMemoryUserSessionStore.cs @@ -13,8 +13,7 @@ public class InMemoryUserSessionStore : IUserSessionStore public Task GetAsync(string key, CancellationToken token = default) { - if (key == null) - throw new ArgumentNullException(nameof(key)); + ArgumentNullException.ThrowIfNull(key); token.ThrowIfCancellationRequested(); @@ -35,8 +34,7 @@ public class InMemoryUserSessionStore : IUserSessionStore public Task AddAsync(UserSession session, CancellationToken token = default) { - if (session == null) - throw new ArgumentNullException(nameof(session)); + ArgumentNullException.ThrowIfNull(session); token.ThrowIfCancellationRequested(); @@ -47,11 +45,8 @@ public Task AddAsync(UserSession session, CancellationToken token = default) public Task UpdateAsync(string key, UserSession session, CancellationToken token = default) { - if (key == null) - throw new ArgumentNullException(nameof(key)); - - if (session == null) - throw new ArgumentNullException(nameof(session)); + ArgumentNullException.ThrowIfNull(key); + ArgumentNullException.ThrowIfNull(session); token.ThrowIfCancellationRequested(); @@ -62,8 +57,7 @@ public Task UpdateAsync(string key, UserSession session, CancellationToken token public Task DeleteAsync(string key, CancellationToken token = default) { - if (key == null) - throw new ArgumentNullException(nameof(key)); + ArgumentNullException.ThrowIfNull(key); token.ThrowIfCancellationRequested(); @@ -74,8 +68,7 @@ public Task DeleteAsync(string key, CancellationToken token = default) public Task DeleteBySessionIdAsync(string sessionId, CancellationToken token = default) { - if (sessionId == null) - throw new ArgumentNullException(nameof(sessionId)); + ArgumentNullException.ThrowIfNull(sessionId); token.ThrowIfCancellationRequested(); diff --git a/src/AspNetCore/Authentication/Authentication/src/Infrastructure/UserSessionTicketStore.cs b/src/AspNetCore/Authentication/Authentication/src/Infrastructure/UserSessionTicketStore.cs index 2b1f38b..aec0bc0 100644 --- a/src/AspNetCore/Authentication/Authentication/src/Infrastructure/UserSessionTicketStore.cs +++ b/src/AspNetCore/Authentication/Authentication/src/Infrastructure/UserSessionTicketStore.cs @@ -77,8 +77,7 @@ private UserSession CreateUserSession(string key, AuthenticationTicket ticket) if (string.IsNullOrWhiteSpace(key)) throw new InvalidOperationException("Invalid key"); - if (ticket == null) - throw new ArgumentNullException(nameof(ticket)); + ArgumentNullException.ThrowIfNull(ticket); var subject = ticket.Principal.FindFirst(JwtClaimTypes.Subject)?.Value; var sessionId = ticket.Principal.FindFirst(JwtClaimTypes.SessionId)?.Value; diff --git a/src/AspNetCore/Authentication/Authentication/src/ServiceCollectionExtensions.cs b/src/AspNetCore/Authentication/Authentication/src/ServiceCollectionExtensions.cs index 6249d43..25e1b7e 100644 --- a/src/AspNetCore/Authentication/Authentication/src/ServiceCollectionExtensions.cs +++ b/src/AspNetCore/Authentication/Authentication/src/ServiceCollectionExtensions.cs @@ -23,11 +23,8 @@ public static OpenIdConnectSessionHandlerBuilder AddOpenIdConnectSessionHandler( this IServiceCollection services, Action configure) { - if (services == null) - throw new ArgumentNullException(nameof(services)); - - if (configure == null) - throw new ArgumentNullException(nameof(configure)); + ArgumentNullException.ThrowIfNull(services); + ArgumentNullException.ThrowIfNull(configure); services.AddOptions() .Validate(o => diff --git a/src/AspNetCore/Authentication/StackExchangeRedis/src/BuilderExtensions.cs b/src/AspNetCore/Authentication/StackExchangeRedis/src/BuilderExtensions.cs index f48760f..599c1e0 100644 --- a/src/AspNetCore/Authentication/StackExchangeRedis/src/BuilderExtensions.cs +++ b/src/AspNetCore/Authentication/StackExchangeRedis/src/BuilderExtensions.cs @@ -16,11 +16,8 @@ public static OpenIdConnectSessionHandlerBuilder AddStackExchangeRedisUserSessio this OpenIdConnectSessionHandlerBuilder builder, Action configure) { - if (builder == null) - throw new ArgumentNullException(nameof(builder)); - - if (configure == null) - throw new ArgumentNullException(nameof(configure)); + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(configure); builder.Services.AddOptions() .Validate(o => diff --git a/src/AspNetCore/Authentication/StackExchangeRedis/src/RedisUserSessionStore.cs b/src/AspNetCore/Authentication/StackExchangeRedis/src/RedisUserSessionStore.cs index 0165fef..d86dc3d 100644 --- a/src/AspNetCore/Authentication/StackExchangeRedis/src/RedisUserSessionStore.cs +++ b/src/AspNetCore/Authentication/StackExchangeRedis/src/RedisUserSessionStore.cs @@ -14,12 +14,11 @@ public class RedisUserSessionStore : IUserSessionStore public RedisUserSessionStore(IOptions cacheOptions) { - if (cacheOptions == null) throw new ArgumentNullException(nameof(cacheOptions)); + ArgumentNullException.ThrowIfNull(cacheOptions); var options = cacheOptions.Value; if (options == null) throw new ArgumentException("Options cannot be null"); - if (options.Connection == null) throw new ArgumentException("Connection cannot be null"); _database = options.Connection.GetDatabase(); @@ -32,8 +31,7 @@ public RedisUserSessionStore(IOptions cacheOptions public async Task AddAsync(UserSession session, CancellationToken token = default) { - if (session == null) - throw new ArgumentNullException(nameof(session)); + ArgumentNullException.ThrowIfNull(session); token.ThrowIfCancellationRequested(); @@ -47,11 +45,8 @@ public async Task AddAsync(UserSession session, CancellationToken token = defaul public async Task UpdateAsync(string key, UserSession session, CancellationToken token = default) { - if (key == null) - throw new ArgumentNullException(nameof(key)); - - if (session == null) - throw new ArgumentNullException(nameof(session)); + ArgumentNullException.ThrowIfNull(key); + ArgumentNullException.ThrowIfNull(session); token.ThrowIfCancellationRequested(); @@ -70,8 +65,7 @@ public async Task UpdateAsync(string key, UserSession session, CancellationToken public async Task DeleteAsync(string key, CancellationToken token = default) { - if (key == null) - throw new ArgumentNullException(nameof(key)); + ArgumentNullException.ThrowIfNull(key); token.ThrowIfCancellationRequested(); @@ -87,8 +81,7 @@ public async Task DeleteAsync(string key, CancellationToken token = default) public async Task DeleteBySessionIdAsync(string sessionId, CancellationToken token = default) { - if (sessionId == null) - throw new ArgumentNullException(nameof(sessionId)); + ArgumentNullException.ThrowIfNull(sessionId); token.ThrowIfCancellationRequested(); @@ -108,8 +101,7 @@ public async Task DeleteBySessionIdAsync(string sessionId, CancellationToken tok private async Task GetInternalAsync(string key, CancellationToken token = default) { - if (key == null) - throw new ArgumentNullException(nameof(key)); + ArgumentNullException.ThrowIfNull(key); token.ThrowIfCancellationRequested();