From 5f2c0daeda7a62a19ed530a5cb506255f72dd7b7 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 23 Mar 2024 10:25:06 -0500 Subject: [PATCH] remove some defensive ArgumentNullExceptions that nullable reference types sufficiently warn about --- TASVideos.Common/Extensions/EnumerableExtensions.cs | 5 ----- TASVideos/Extensions/HtmlHelperExtensions.cs | 10 ---------- TASVideos/Extensions/HttpRequestExtensions.cs | 5 ----- TASVideos/Models/CommaSeparatedModelBinder.cs | 5 ----- 4 files changed, 25 deletions(-) diff --git a/TASVideos.Common/Extensions/EnumerableExtensions.cs b/TASVideos.Common/Extensions/EnumerableExtensions.cs index 6ecfe07e2..e064d1fff 100644 --- a/TASVideos.Common/Extensions/EnumerableExtensions.cs +++ b/TASVideos.Common/Extensions/EnumerableExtensions.cs @@ -31,11 +31,6 @@ public static IEnumerable SecondHalf(this IEnumerable source) /// public static T AtRandom(this ICollection collection) { - if (collection is null) - { - throw new ArgumentNullException($"{nameof(collection)} can not be null"); - } - var randomIndex = new Random(DateTime.UtcNow.Millisecond).Next(0, collection.Count); return collection.ElementAt(randomIndex); } diff --git a/TASVideos/Extensions/HtmlHelperExtensions.cs b/TASVideos/Extensions/HtmlHelperExtensions.cs index 94818a032..07579120e 100644 --- a/TASVideos/Extensions/HtmlHelperExtensions.cs +++ b/TASVideos/Extensions/HtmlHelperExtensions.cs @@ -9,16 +9,6 @@ public static class HtmlHelperExtensions { public static IHtmlContent DescriptionFor(this IHtmlHelper html, Expression> expression) { - if (html is null) - { - throw new ArgumentNullException(nameof(html)); - } - - if (expression is null) - { - throw new ArgumentNullException(nameof(expression)); - } - var expressionProvider = html.ViewContext.HttpContext.RequestServices.GetRequiredService(); var modelExpression = expressionProvider.CreateModelExpression(html.ViewData, expression); diff --git a/TASVideos/Extensions/HttpRequestExtensions.cs b/TASVideos/Extensions/HttpRequestExtensions.cs index bbbda5b2e..29f2d4625 100644 --- a/TASVideos/Extensions/HttpRequestExtensions.cs +++ b/TASVideos/Extensions/HttpRequestExtensions.cs @@ -10,11 +10,6 @@ public static class HttpRequestExtensions public static bool IsAjaxRequest(this HttpRequest request) { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - return request.Headers[RequestedWithHeader] == XmlHttpRequest; } diff --git a/TASVideos/Models/CommaSeparatedModelBinder.cs b/TASVideos/Models/CommaSeparatedModelBinder.cs index 1268ff0b4..4a8939c68 100644 --- a/TASVideos/Models/CommaSeparatedModelBinder.cs +++ b/TASVideos/Models/CommaSeparatedModelBinder.cs @@ -20,11 +20,6 @@ public class DelimitedQueryStringValueProvider( public override ValueProviderResult GetValue(string key) { - if (key is null) - { - throw new ArgumentNullException(nameof(key)); - } - var values = _queryCollection[key]; if (values.Count == 0) {