diff --git a/ICD.Common.Utils.Tests/Extensions/ListExtensionsTest.cs b/ICD.Common.Utils.Tests/Extensions/ListExtensionsTest.cs index 28775fb..31644df 100644 --- a/ICD.Common.Utils.Tests/Extensions/ListExtensionsTest.cs +++ b/ICD.Common.Utils.Tests/Extensions/ListExtensionsTest.cs @@ -13,10 +13,10 @@ namespace ICD.Common.Utils.Tests.Extensions { List testList = new List(); - testList.AddSorted(2); - testList.AddSorted(3); - testList.AddSorted(1); - testList.AddSorted(2); + Assert.AreEqual(0, testList.AddSorted(2)); + Assert.AreEqual(1, testList.AddSorted(3)); + Assert.AreEqual(0, testList.AddSorted(1)); + Assert.AreEqual(1, testList.AddSorted(2)); Assert.AreEqual(4, testList.Count); Assert.AreEqual(1, testList[0]); @@ -31,10 +31,10 @@ namespace ICD.Common.Utils.Tests.Extensions List testList = new List(); IComparer comparer = new InverseComparer(); - testList.AddSorted(2, comparer); - testList.AddSorted(3, comparer); - testList.AddSorted(1, comparer); - testList.AddSorted(2, comparer); + Assert.AreEqual(0, testList.AddSorted(2, comparer)); + Assert.AreEqual(0, testList.AddSorted(3, comparer)); + Assert.AreEqual(2, testList.AddSorted(1, comparer)); + Assert.AreEqual(1, testList.AddSorted(2, comparer)); Assert.AreEqual(4, testList.Count); Assert.AreEqual(3, testList[0]); diff --git a/ICD.Common.Utils/Extensions/ListExtensions.cs b/ICD.Common.Utils/Extensions/ListExtensions.cs index c50c031..04d32b1 100644 --- a/ICD.Common.Utils/Extensions/ListExtensions.cs +++ b/ICD.Common.Utils/Extensions/ListExtensions.cs @@ -82,12 +82,12 @@ namespace ICD.Common.Utils.Extensions /// /// [PublicAPI] - public static void AddSorted(this List extends, T item) + public static int AddSorted(this List extends, T item) { if (extends == null) throw new ArgumentNullException("extends"); - extends.AddSorted(item, Comparer.Default); + return extends.AddSorted(item, Comparer.Default); } /// @@ -98,7 +98,7 @@ namespace ICD.Common.Utils.Extensions /// /// [PublicAPI] - public static void AddSorted(this List extends, T item, IComparer comparer) + public static int AddSorted(this List extends, T item, IComparer comparer) { if (extends == null) throw new ArgumentNullException("extends"); @@ -111,6 +111,8 @@ namespace ICD.Common.Utils.Extensions index = ~index; extends.Insert(index, item); + + return index; } /// @@ -122,7 +124,7 @@ namespace ICD.Common.Utils.Extensions /// /// [PublicAPI] - public static void AddSorted(this List extends, T item, Func predicate) + public static int AddSorted(this List extends, T item, Func predicate) { if (extends == null) throw new ArgumentNullException("extends"); @@ -131,7 +133,7 @@ namespace ICD.Common.Utils.Extensions throw new ArgumentNullException("predicate"); PredicateComparer comparer = new PredicateComparer(predicate); - extends.AddSorted(item, comparer); + return extends.AddSorted(item, comparer); } ///