From 9e715d37904dd9cf8d7d6b14a522120767e9c518 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Tue, 17 Apr 2018 14:05:32 -0400 Subject: [PATCH] feat: Util methods for inserting items into a sorted list by a predicate --- ICD.Common.Utils/Extensions/ListExtensions.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/ICD.Common.Utils/Extensions/ListExtensions.cs b/ICD.Common.Utils/Extensions/ListExtensions.cs index 68642f9..50c28c7 100644 --- a/ICD.Common.Utils/Extensions/ListExtensions.cs +++ b/ICD.Common.Utils/Extensions/ListExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using ICD.Common.Properties; +using ICD.Common.Utils.Comparers; namespace ICD.Common.Utils.Extensions { @@ -50,6 +51,30 @@ namespace ICD.Common.Utils.Extensions items.ForEach(i => extends.AddSorted(i, comparer)); } + /// + /// Adds the items into a sorted list. + /// + /// + /// + /// + /// + /// + [PublicAPI] + public static void AddSorted(this List extends, IEnumerable items, Func predicate) + { + if (extends == null) + throw new ArgumentNullException("extends"); + + if (items == null) + throw new ArgumentNullException("items"); + + if (predicate == null) + throw new ArgumentNullException("predicate"); + + PredicateComparer comparer = new PredicateComparer(predicate); + extends.AddSorted(items, comparer); + } + /// /// Adds the item into a sorted list. /// @@ -106,6 +131,27 @@ namespace ICD.Common.Utils.Extensions extends.Insert(index, item); } + /// + /// Adds the item into a sorted list. + /// + /// + /// + /// + /// + /// + [PublicAPI] + public static void AddSorted(this List extends, T item, Func predicate) + { + if (extends == null) + throw new ArgumentNullException("extends"); + + if (predicate == null) + throw new ArgumentNullException("predicate"); + + PredicateComparer comparer = new PredicateComparer(predicate); + extends.AddSorted(item, comparer); + } + /// /// Pads the list to the given total length. ///