Skip to content

Commit 2a9f898

Browse files
author
David McCarter
committed
Refactor ListExtensions methods and update metadata
Updated the metadata comment in `ListExtensions.cs` to reflect a new modification date (10-29-2024). Modified the `Information` attribute for `AddFirst` and `AddLast` methods, changing `BenchMarkStatus` from `NotRequired` to `CheckPerformance`. Refactored `AddFirst` to validate the collection and insert the item at the beginning. Refactored `AddLast` to validate the collection and add the item to the end.
1 parent 4d66e79 commit 2a9f898

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

source/dotNetTips.Spargine.8.Extensions/ListExtensions.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Created : 02-14-2018
55
//
66
// Last Modified By : David McCarter
7-
// Last Modified On : 10-15-2024
7+
// Last Modified On : 10-29-2024
88
// ***********************************************************************
99
// <copyright file="ListExtensions.cs" company="McCarter Consulting">
1010
// McCarter Consulting (David McCarter)
@@ -46,15 +46,17 @@ public static class ListExtensions
4646
/// <param name="item">The item to add to the beginning of the list.</param>
4747
/// <exception cref="ArgumentNullException">Thrown if <paramref name="collection"/> or <paramref name="item"/> is null.</exception>
4848
[MethodImpl(MethodImplOptions.AggressiveInlining)]
49-
[Information("From .NET Core source.", author: "David McCarter", createdOn: "7/15/2020", UnitTestStatus = UnitTestStatus.Completed, BenchMarkStatus = BenchMarkStatus.NotRequired, Status = Status.Available)]
49+
[Information("From .NET Core source.", author: "David McCarter", createdOn: "7/15/2020", UnitTestStatus = UnitTestStatus.Completed, BenchMarkStatus = BenchMarkStatus.CheckPerformance, Status = Status.Available)]
5050
public static List<T> AddFirst<T>([NotNull] this List<T> collection, [NotNull] T item)
5151
{
5252
if (item is null)
5353
{
5454
return collection;
5555
}
5656

57-
return collection.ArgumentNotNull().ArgumentNotReadOnly().Prepend(item).ToList();
57+
_ = collection.ArgumentNotNull().ArgumentNotReadOnly();
58+
collection.Insert(0, item);
59+
return collection;
5860
}
5961

6062
/// <summary>
@@ -65,16 +67,17 @@ public static List<T> AddFirst<T>([NotNull] this List<T> collection, [NotNull] T
6567
/// <param name="item">The item to add to the end of the list.</param>
6668
/// <exception cref="ArgumentNullException">Thrown if <paramref name="collection"/> or <paramref name="item"/> is null.</exception>
6769
[MethodImpl(MethodImplOptions.AggressiveInlining)]
68-
[Information("From .NET Core source.", author: "David McCarter", createdOn: "7/15/2020", UnitTestStatus = UnitTestStatus.Completed, BenchMarkStatus = BenchMarkStatus.NotRequired, Status = Status.Available)]
70+
[Information("From .NET Core source.", author: "David McCarter", createdOn: "7/15/2020", UnitTestStatus = UnitTestStatus.Completed, BenchMarkStatus = BenchMarkStatus.CheckPerformance, Status = Status.Available)]
6971
public static List<T> AddLast<T>([NotNull] this List<T> collection, [NotNull] T item)
7072
{
7173
if (item is null)
7274
{
7375
return collection;
7476
}
7577

76-
return [.. collection.ArgumentNotNull().ArgumentNotReadOnly(), item];
77-
78+
_ = collection.ArgumentNotNull().ArgumentNotReadOnly();
79+
collection.Add(item);
80+
return collection;
7881
}
7982

8083
/// <summary>

0 commit comments

Comments
 (0)