diff --git a/src/Http/Routing/src/Builder/EndpointRouteBuilderExtensions.cs b/src/Http/Routing/src/Builder/EndpointRouteBuilderExtensions.cs index 058304686084..178646a77a0b 100644 --- a/src/Http/Routing/src/Builder/EndpointRouteBuilderExtensions.cs +++ b/src/Http/Routing/src/Builder/EndpointRouteBuilderExtensions.cs @@ -51,8 +51,8 @@ public static GroupRouteBuilder MapGroup(this IEndpointRouteBuilder endpoints, s /// public static GroupRouteBuilder MapGroup(this IEndpointRouteBuilder endpoints, RoutePattern prefix) { - ArgumentNullException.ThrowIfNull(endpoints, nameof(endpoints)); - ArgumentNullException.ThrowIfNull(prefix, nameof(prefix)); + ArgumentNullException.ThrowIfNull(endpoints); + ArgumentNullException.ThrowIfNull(prefix); return new(endpoints, prefix); } @@ -158,10 +158,7 @@ public static IEndpointConventionBuilder MapMethods( IEnumerable httpMethods, RequestDelegate requestDelegate) { - if (httpMethods == null) - { - throw new ArgumentNullException(nameof(httpMethods)); - } + ArgumentNullException.ThrowIfNull(httpMethods); var builder = endpoints.Map(RoutePatternFactory.Parse(pattern), requestDelegate); builder.WithDisplayName($"{pattern} HTTP: {string.Join(", ", httpMethods)}"); @@ -198,20 +195,9 @@ public static IEndpointConventionBuilder Map( RoutePattern pattern, RequestDelegate requestDelegate) { - if (endpoints == null) - { - throw new ArgumentNullException(nameof(endpoints)); - } - - if (pattern == null) - { - throw new ArgumentNullException(nameof(pattern)); - } - - if (requestDelegate == null) - { - throw new ArgumentNullException(nameof(requestDelegate)); - } + ArgumentNullException.ThrowIfNull(endpoints); + ArgumentNullException.ThrowIfNull(pattern); + ArgumentNullException.ThrowIfNull(requestDelegate); const int defaultOrder = 0; @@ -346,10 +332,7 @@ public static RouteHandlerBuilder MapMethods( IEnumerable httpMethods, Delegate handler) { - if (httpMethods is null) - { - throw new ArgumentNullException(nameof(httpMethods)); - } + ArgumentNullException.ThrowIfNull(httpMethods); var disableInferredBody = false; foreach (var method in httpMethods) @@ -437,15 +420,8 @@ public static RouteHandlerBuilder Map( [RequiresUnreferencedCode(MapEndpointTrimmerWarning)] public static RouteHandlerBuilder MapFallback(this IEndpointRouteBuilder endpoints, Delegate handler) { - if (endpoints == null) - { - throw new ArgumentNullException(nameof(endpoints)); - } - - if (handler == null) - { - throw new ArgumentNullException(nameof(handler)); - } + ArgumentNullException.ThrowIfNull(endpoints); + ArgumentNullException.ThrowIfNull(handler); return endpoints.MapFallback("{*path:nonfile}", handler); } @@ -477,20 +453,9 @@ public static RouteHandlerBuilder MapFallback( string pattern, Delegate handler) { - if (endpoints == null) - { - throw new ArgumentNullException(nameof(endpoints)); - } - - if (pattern == null) - { - throw new ArgumentNullException(nameof(pattern)); - } - - if (handler == null) - { - throw new ArgumentNullException(nameof(handler)); - } + ArgumentNullException.ThrowIfNull(endpoints); + ArgumentNullException.ThrowIfNull(pattern); + ArgumentNullException.ThrowIfNull(handler); var conventionBuilder = endpoints.Map(pattern, handler); conventionBuilder.WithDisplayName("Fallback " + pattern); @@ -506,20 +471,9 @@ private static RouteHandlerBuilder Map( bool disableInferBodyFromParameters, IEnumerable? initialEndpointMetadata = null) { - if (endpoints is null) - { - throw new ArgumentNullException(nameof(endpoints)); - } - - if (pattern is null) - { - throw new ArgumentNullException(nameof(pattern)); - } - - if (handler is null) - { - throw new ArgumentNullException(nameof(handler)); - } + ArgumentNullException.ThrowIfNull(endpoints); + ArgumentNullException.ThrowIfNull(pattern); + ArgumentNullException.ThrowIfNull(handler); const int defaultOrder = 0; diff --git a/src/Http/Routing/src/Builder/EndpointRoutingApplicationBuilderExtensions.cs b/src/Http/Routing/src/Builder/EndpointRoutingApplicationBuilderExtensions.cs index 69c7da5e8eed..6d14b6bd980e 100644 --- a/src/Http/Routing/src/Builder/EndpointRoutingApplicationBuilderExtensions.cs +++ b/src/Http/Routing/src/Builder/EndpointRoutingApplicationBuilderExtensions.cs @@ -37,10 +37,7 @@ public static class EndpointRoutingApplicationBuilderExtensions /// public static IApplicationBuilder UseRouting(this IApplicationBuilder builder) { - if (builder == null) - { - throw new ArgumentNullException(nameof(builder)); - } + ArgumentNullException.ThrowIfNull(builder); VerifyRoutingServicesAreRegistered(builder); @@ -85,15 +82,8 @@ public static IApplicationBuilder UseRouting(this IApplicationBuilder builder) /// public static IApplicationBuilder UseEndpoints(this IApplicationBuilder 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); VerifyRoutingServicesAreRegistered(builder); diff --git a/src/Http/Routing/src/Builder/FallbackEndpointRouteBuilderExtensions.cs b/src/Http/Routing/src/Builder/FallbackEndpointRouteBuilderExtensions.cs index 25082d9de5d0..8dd7c1e90aa3 100644 --- a/src/Http/Routing/src/Builder/FallbackEndpointRouteBuilderExtensions.cs +++ b/src/Http/Routing/src/Builder/FallbackEndpointRouteBuilderExtensions.cs @@ -37,15 +37,8 @@ public static class FallbackEndpointRouteBuilderExtensions /// public static IEndpointConventionBuilder MapFallback(this IEndpointRouteBuilder endpoints, RequestDelegate requestDelegate) { - if (endpoints == null) - { - throw new ArgumentNullException(nameof(endpoints)); - } - - if (requestDelegate == null) - { - throw new ArgumentNullException(nameof(requestDelegate)); - } + ArgumentNullException.ThrowIfNull(endpoints); + ArgumentNullException.ThrowIfNull(requestDelegate); return endpoints.MapFallback("{*path:nonfile}", requestDelegate); } @@ -76,20 +69,9 @@ public static IEndpointConventionBuilder MapFallback( string pattern, RequestDelegate requestDelegate) { - if (endpoints == null) - { - throw new ArgumentNullException(nameof(endpoints)); - } - - if (pattern == null) - { - throw new ArgumentNullException(nameof(pattern)); - } - - if (requestDelegate == null) - { - throw new ArgumentNullException(nameof(requestDelegate)); - } + ArgumentNullException.ThrowIfNull(endpoints); + ArgumentNullException.ThrowIfNull(pattern); + ArgumentNullException.ThrowIfNull(requestDelegate); var conventionBuilder = endpoints.Map(pattern, requestDelegate); conventionBuilder.WithDisplayName("Fallback " + pattern); diff --git a/src/Http/Routing/src/Builder/RoutingBuilderExtensions.cs b/src/Http/Routing/src/Builder/RoutingBuilderExtensions.cs index 3dcbef76c9cd..6dd8316c0fa6 100644 --- a/src/Http/Routing/src/Builder/RoutingBuilderExtensions.cs +++ b/src/Http/Routing/src/Builder/RoutingBuilderExtensions.cs @@ -19,15 +19,8 @@ public static class RoutingBuilderExtensions /// A reference to this instance after the operation has completed. public static IApplicationBuilder UseRouter(this IApplicationBuilder builder, IRouter router) { - if (builder == null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (router == null) - { - throw new ArgumentNullException(nameof(router)); - } + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(router); if (builder.ApplicationServices.GetService(typeof(RoutingMarkerService)) == null) { @@ -49,15 +42,8 @@ public static IApplicationBuilder UseRouter(this IApplicationBuilder builder, IR /// A reference to this instance after the operation has completed. public static IApplicationBuilder UseRouter(this IApplicationBuilder builder, Action action) { - if (builder == null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (action == null) - { - throw new ArgumentNullException(nameof(action)); - } + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(action); if (builder.ApplicationServices.GetService(typeof(RoutingMarkerService)) == null) { diff --git a/src/Http/Routing/src/Builder/RoutingEndpointConventionBuilderExtensions.cs b/src/Http/Routing/src/Builder/RoutingEndpointConventionBuilderExtensions.cs index e2b64bab0303..258391f87b60 100644 --- a/src/Http/Routing/src/Builder/RoutingEndpointConventionBuilderExtensions.cs +++ b/src/Http/Routing/src/Builder/RoutingEndpointConventionBuilderExtensions.cs @@ -22,15 +22,8 @@ public static class RoutingEndpointConventionBuilderExtensions /// A reference to this instance after the operation has completed. public static TBuilder RequireHost(this TBuilder builder, params string[] hosts) where TBuilder : IEndpointConventionBuilder { - if (builder == null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (hosts == null) - { - throw new ArgumentNullException(nameof(hosts)); - } + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(hosts); builder.Add(endpointBuilder => { @@ -48,10 +41,7 @@ public static TBuilder RequireHost(this TBuilder builder, params strin /// The . public static TBuilder WithDisplayName(this TBuilder builder, string displayName) where TBuilder : IEndpointConventionBuilder { - if (builder == null) - { - throw new ArgumentNullException(nameof(builder)); - } + ArgumentNullException.ThrowIfNull(builder); builder.Add(b => { @@ -70,15 +60,8 @@ public static TBuilder WithDisplayName(this TBuilder builder, string d /// The . public static TBuilder WithDisplayName(this TBuilder builder, Func func) where TBuilder : IEndpointConventionBuilder { - if (builder == null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (func == null) - { - throw new ArgumentNullException(nameof(func)); - } + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(func); builder.Add(b => { @@ -97,15 +80,8 @@ public static TBuilder WithDisplayName(this TBuilder builder, FuncThe . public static TBuilder WithMetadata(this TBuilder builder, params object[] items) where TBuilder : IEndpointConventionBuilder { - if (builder == null) - { - throw new ArgumentNullException(nameof(builder)); - } - - if (items == null) - { - throw new ArgumentNullException(nameof(items)); - } + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(items); builder.Add(b => {