mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using ICD.Common.Utils.Extensions;
|
||||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
|
||||
namespace ICD.Common.Utils.Tests_NetStandard.Extensions
|
||||
{
|
||||
[TestFixture]
|
||||
public sealed class EnumerableExtensionsTest
|
||||
{
|
||||
[Test]
|
||||
public void ConsolidateTest()
|
||||
{
|
||||
string[] sequence = EnumerableExtensions.Consolidate(new string[] { "A", "B", "B", "C" }).ToArray();
|
||||
|
||||
Assert.AreEqual(3, sequence.Length, StringUtils.ArrayFormat(sequence));
|
||||
Assert.AreEqual("A", sequence[0]);
|
||||
Assert.AreEqual("B", sequence[1]);
|
||||
Assert.AreEqual("C", sequence[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -644,7 +644,7 @@ namespace ICD.Common.Utils.Extensions
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static IEnumerable<T> Consolidate<T>(IEnumerable<T> extends)
|
||||
public static IEnumerable<T> Consolidate<T>(this IEnumerable<T> extends)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
@@ -664,7 +664,7 @@ namespace ICD.Common.Utils.Extensions
|
||||
/// <param name="comparer"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static IEnumerable<T> Consolidate<T>(IEnumerable<T> extends, IComparer<T> comparer)
|
||||
public static IEnumerable<T> Consolidate<T>(this IEnumerable<T> extends, IComparer<T> comparer)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
@@ -677,7 +677,7 @@ namespace ICD.Common.Utils.Extensions
|
||||
|
||||
foreach (T item in extends)
|
||||
{
|
||||
if (!first && comparer.Compare(last, item) != 0)
|
||||
if (!first && comparer.Compare(last, item) == 0)
|
||||
continue;
|
||||
|
||||
first = false;
|
||||
|
||||
@@ -115,6 +115,16 @@ namespace ICD.Common.Utils
|
||||
return string.Join("", strings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses String.Format to properly handle null values.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToString(object value)
|
||||
{
|
||||
return string.Format("{0}", value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts bytes to an ascii string.
|
||||
/// </summary>
|
||||
@@ -360,7 +370,7 @@ namespace ICD.Common.Utils
|
||||
if (items == null)
|
||||
throw new ArgumentNullException("items");
|
||||
|
||||
return string.Format("[{0}]", string.Join(", ", items.Select(i => i.ToString()).ToArray()));
|
||||
return string.Format("[{0}]", string.Join(", ", items.Select(i => ToString(i)).ToArray()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -377,7 +387,7 @@ namespace ICD.Common.Utils
|
||||
|
||||
string[] ranges = MathUtils.GetRanges(items)
|
||||
.Select(r => r[0] == r[1]
|
||||
? r[0].ToString()
|
||||
? ToString(r[0])
|
||||
: string.Format("{0}-{1}", r[0], r[1]))
|
||||
.ToArray();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user