From 99bdbccf85fcf99660d17c5c9203ffdad8a7cb70 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Mon, 25 Apr 2022 10:11:42 +0100 Subject: [PATCH] Declare Fill for IList not T[] --- X10D/src/Collections/ArrayExtensions.cs | 22 ---------------------- X10D/src/Collections/ListExtensions.cs | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/X10D/src/Collections/ArrayExtensions.cs b/X10D/src/Collections/ArrayExtensions.cs index a6db95e..32e094b 100644 --- a/X10D/src/Collections/ArrayExtensions.cs +++ b/X10D/src/Collections/ArrayExtensions.cs @@ -87,28 +87,6 @@ public static class ArrayExtensions Array.Clear(array, index, length); } - /// - /// Assigns the given value to each element of the array. - /// - /// The array to be filled. - /// The value to assign to each array element. - /// The type of the elements in the array. - /// is . - public static void Fill(this T?[] array, T value) - { - if (array is null) - { - throw new ArgumentNullException(nameof(array)); - } - - if (array.Length == 0) - { - return; - } - - Array.Fill(array, value); - } - /// /// Assigns the given value to the elements of the array which are within the range of /// (inclusive) and the next number of indices. diff --git a/X10D/src/Collections/ListExtensions.cs b/X10D/src/Collections/ListExtensions.cs index 7fb8ce4..1444287 100644 --- a/X10D/src/Collections/ListExtensions.cs +++ b/X10D/src/Collections/ListExtensions.cs @@ -5,6 +5,26 @@ /// public static class ListExtensions { + /// + /// Assigns the given value to each element of the list. + /// + /// The list to be filled. + /// The value to assign to each list element. + /// The type of the elements in the list. + /// is . + public static void Fill(this IList source, T value) + { + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } + + for (var i = 0; i < source.Count; i++) + { + source[i] = value; + } + } + /// /// Returns a random element from the current list using a specified instance. ///