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/AspNetCore/src/Middleware/DefaultHeaders/ApplicationBuilderExtensions.cs b/src/AspNetCore/AspNetCore/src/Middleware/DefaultHeaders/ApplicationBuilderExtensions.cs
index 3d12204..40cbe78 100644
--- a/src/AspNetCore/AspNetCore/src/Middleware/DefaultHeaders/ApplicationBuilderExtensions.cs
+++ b/src/AspNetCore/AspNetCore/src/Middleware/DefaultHeaders/ApplicationBuilderExtensions.cs
@@ -18,17 +18,10 @@ public static class ApplicationBuilderExtensions
public static void UseDefaultHeaders(this IApplicationBuilder app,
DefaultHeadersMiddlewareOptions options)
{
- if (app == null)
- {
- throw new ArgumentNullException(nameof(app));
- }
-
- if (options == null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ ArgumentNullException.ThrowIfNull(app);
+ ArgumentNullException.ThrowIfNull(options);
app.UseMiddleware(Options.Create(options));
}
}
-}
\ No newline at end of file
+}
diff --git a/src/AspNetCore/AspNetCore/src/Routing/KebabCaseParameterTransformer.cs b/src/AspNetCore/AspNetCore/src/Routing/KebabCaseParameterTransformer.cs
index 0608992..d363f42 100644
--- a/src/AspNetCore/AspNetCore/src/Routing/KebabCaseParameterTransformer.cs
+++ b/src/AspNetCore/AspNetCore/src/Routing/KebabCaseParameterTransformer.cs
@@ -8,6 +8,8 @@ namespace ClickView.GoodStuff.AspNetCore.Routing;
///
public class KebabCaseParameterTransformer : IOutboundParameterTransformer
{
+ private static readonly Regex ReplacerRegex = new("([a-z])([A-Z])", RegexOptions.Compiled);
+
///
public string? TransformOutbound(object? value)
{
@@ -17,6 +19,6 @@ public class KebabCaseParameterTransformer : IOutboundParameterTransformer
return null;
// Slugify value
- return Regex.Replace(str, "([a-z])([A-Z])", "$1-$2");
+ return ReplacerRegex.Replace(str, "$1-$2");
}
}
diff --git a/src/AspNetCore/AspNetCore/src/VersionPage/VersionPageMiddleware.cs b/src/AspNetCore/AspNetCore/src/VersionPage/VersionPageMiddleware.cs
index 717eb3b..385ce38 100644
--- a/src/AspNetCore/AspNetCore/src/VersionPage/VersionPageMiddleware.cs
+++ b/src/AspNetCore/AspNetCore/src/VersionPage/VersionPageMiddleware.cs
@@ -14,14 +14,9 @@ public sealed class VersionPageMiddleware
public VersionPageMiddleware(RequestDelegate next, ApplicationInformation applicationInformation,
IOptions options)
{
- if (next == null)
- throw new ArgumentNullException(nameof(next));
-
- if (applicationInformation == null)
- throw new ArgumentNullException(nameof(applicationInformation));
-
- if (options == null)
- throw new ArgumentNullException(nameof(options));
+ ArgumentNullException.ThrowIfNull(next);
+ ArgumentNullException.ThrowIfNull(applicationInformation);
+ ArgumentNullException.ThrowIfNull(options);
_next = next;
_applicationInformation = applicationInformation;
@@ -30,8 +25,7 @@ public VersionPageMiddleware(RequestDelegate next, ApplicationInformation applic
public async Task InvokeAsync(HttpContext httpContext)
{
- if (httpContext == null)
- throw new ArgumentNullException(nameof(httpContext));
+ ArgumentNullException.ThrowIfNull(httpContext);
httpContext.Response.StatusCode = 200;
diff --git a/src/AspNetCore/Authentication/Authentication/src/InMemoryUserSessionStore.cs b/src/AspNetCore/Authentication/Authentication/src/InMemoryUserSessionStore.cs
index db9ff54..3a18dc1 100644
--- a/src/AspNetCore/Authentication/Authentication/src/InMemoryUserSessionStore.cs
+++ b/src/AspNetCore/Authentication/Authentication/src/InMemoryUserSessionStore.cs
@@ -9,13 +9,11 @@
public class InMemoryUserSessionStore : IUserSessionStore
{
- private readonly ConcurrentDictionary _sessions =
- new ConcurrentDictionary();
+ private readonly ConcurrentDictionary _sessions = new();
public Task GetAsync(string key, CancellationToken token = default)
{
- if (key == null)
- throw new ArgumentNullException(nameof(key));
+ ArgumentNullException.ThrowIfNull(key);
token.ThrowIfCancellationRequested();
@@ -36,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();
@@ -48,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();
@@ -63,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();
@@ -75,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();
diff --git a/src/Repositories/MySql/src/MySqlUtils.cs b/src/Repositories/MySql/src/MySqlUtils.cs
index 482f099..c3d72e4 100644
--- a/src/Repositories/MySql/src/MySqlUtils.cs
+++ b/src/Repositories/MySql/src/MySqlUtils.cs
@@ -13,7 +13,7 @@ public static bool IsFailoverException(MySqlException mySqlException)
{
return mySqlException.Number == (int) MySqlErrorCode.UnableToConnectToHost ||
mySqlException.Number == (int) MySqlErrorCode.OptionPreventsStatement ||
- mySqlException.Number == 0 && mySqlException.HResult == -2147467259;
+ mySqlException is { Number: 0, HResult: -2147467259 };
}
}
}