From 2ceab1dc56cef75983b4c3f8b741d601702531f4 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Wed, 3 Jul 2019 10:44:57 -0500 Subject: [PATCH] throw exception on null argument of IReadOnlyList.FirstOrDefault() --- .../Extensions/ReadOnlyListExtensions.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/FilterLists.Agent/Extensions/ReadOnlyListExtensions.cs b/src/FilterLists.Agent/Extensions/ReadOnlyListExtensions.cs index 093fc24fc..101ca01b0 100644 --- a/src/FilterLists.Agent/Extensions/ReadOnlyListExtensions.cs +++ b/src/FilterLists.Agent/Extensions/ReadOnlyListExtensions.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace FilterLists.Agent.Extensions { @@ -6,9 +7,9 @@ public static class ReadOnlyListExtensions { public static T FirstOrDefault(this IReadOnlyList list) { - if (list is null || list.Count == 0) - return default; - return list[0]; + if (list is null) + throw new ArgumentNullException(nameof(list)); + return list.Count == 0 ? default : list[0]; } } } \ No newline at end of file