mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-15 20:54:58 +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>
|
/// <param name="extends"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static IEnumerable<T> Consolidate<T>(IEnumerable<T> extends)
|
public static IEnumerable<T> Consolidate<T>(this IEnumerable<T> extends)
|
||||||
{
|
{
|
||||||
if (extends == null)
|
if (extends == null)
|
||||||
throw new ArgumentNullException("extends");
|
throw new ArgumentNullException("extends");
|
||||||
@@ -664,7 +664,7 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
/// <param name="comparer"></param>
|
/// <param name="comparer"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[PublicAPI]
|
[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)
|
if (extends == null)
|
||||||
throw new ArgumentNullException("extends");
|
throw new ArgumentNullException("extends");
|
||||||
@@ -677,7 +677,7 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
|
|
||||||
foreach (T item in extends)
|
foreach (T item in extends)
|
||||||
{
|
{
|
||||||
if (!first && comparer.Compare(last, item) != 0)
|
if (!first && comparer.Compare(last, item) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
first = false;
|
first = false;
|
||||||
|
|||||||
@@ -115,6 +115,16 @@ namespace ICD.Common.Utils
|
|||||||
return string.Join("", strings);
|
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>
|
/// <summary>
|
||||||
/// Converts bytes to an ascii string.
|
/// Converts bytes to an ascii string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -360,7 +370,7 @@ namespace ICD.Common.Utils
|
|||||||
if (items == null)
|
if (items == null)
|
||||||
throw new ArgumentNullException("items");
|
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>
|
/// <summary>
|
||||||
@@ -377,7 +387,7 @@ namespace ICD.Common.Utils
|
|||||||
|
|
||||||
string[] ranges = MathUtils.GetRanges(items)
|
string[] ranges = MathUtils.GetRanges(items)
|
||||||
.Select(r => r[0] == r[1]
|
.Select(r => r[0] == r[1]
|
||||||
? r[0].ToString()
|
? ToString(r[0])
|
||||||
: string.Format("{0}-{1}", r[0], r[1]))
|
: string.Format("{0}-{1}", r[0], r[1]))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user