Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings and cleanup #103

Merged
merged 4 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public static class ServiceCollectionExtensions
/// <exception cref="ArgumentNullException"></exception>
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<IAuthorizationMiddlewareResultHandler, AjaxAuthorizationMiddlewareResultHandler>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DefaultHeadersMiddleware>(Options.Create(options));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace ClickView.GoodStuff.AspNetCore.Routing;
/// </summary>
public class KebabCaseParameterTransformer : IOutboundParameterTransformer
{
private static readonly Regex ReplacerRegex = new("([a-z])([A-Z])", RegexOptions.Compiled);

/// <inheritdoc />
public string? TransformOutbound(object? value)
{
Expand All @@ -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");
}
}
14 changes: 4 additions & 10 deletions src/AspNetCore/AspNetCore/src/VersionPage/VersionPageMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@ public sealed class VersionPageMiddleware
public VersionPageMiddleware(RequestDelegate next, ApplicationInformation applicationInformation,
IOptions<VersionPageOptions> 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;
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@

public class InMemoryUserSessionStore : IUserSessionStore
{
private readonly ConcurrentDictionary<string, UserSession> _sessions =
new ConcurrentDictionary<string, UserSession>();
private readonly ConcurrentDictionary<string, UserSession> _sessions = new();

public Task<UserSession?> GetAsync(string key, CancellationToken token = default)
{
if (key == null)
throw new ArgumentNullException(nameof(key));
ArgumentNullException.ThrowIfNull(key);

token.ThrowIfCancellationRequested();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ public static OpenIdConnectSessionHandlerBuilder AddOpenIdConnectSessionHandler(
this IServiceCollection services,
Action<OpenIdConnectSessionHandlerOptions> 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<OpenIdConnectSessionHandlerOptions>()
.Validate(o =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ public static OpenIdConnectSessionHandlerBuilder AddStackExchangeRedisUserSessio
this OpenIdConnectSessionHandlerBuilder builder,
Action<RedisUserSessionCacheOptions> 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<RedisUserSessionCacheOptions>()
.Validate(o =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ public class RedisUserSessionStore : IUserSessionStore

public RedisUserSessionStore(IOptions<RedisUserSessionCacheOptions> 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();
Expand All @@ -32,8 +31,7 @@ public RedisUserSessionStore(IOptions<RedisUserSessionCacheOptions> cacheOptions

public async Task AddAsync(UserSession session, CancellationToken token = default)
{
if (session == null)
throw new ArgumentNullException(nameof(session));
ArgumentNullException.ThrowIfNull(session);

token.ThrowIfCancellationRequested();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -108,8 +101,7 @@ public async Task DeleteBySessionIdAsync(string sessionId, CancellationToken tok

private async Task<UserSession?> GetInternalAsync(string key, CancellationToken token = default)
{
if (key == null)
throw new ArgumentNullException(nameof(key));
ArgumentNullException.ThrowIfNull(key);

token.ThrowIfCancellationRequested();

Expand Down
2 changes: 1 addition & 1 deletion src/Repositories/MySql/src/MySqlUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}
}
Loading