1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 18:58:47 +00:00

Append "Value" to AsArray/AsEnumerable, to reduce risk of LINQ collision

This commit is contained in:
Oliver Booth 2022-04-26 10:45:18 +01:00
parent 6d80ee7a6d
commit f7f3ea71bb
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
4 changed files with 16 additions and 16 deletions

View File

@ -13,7 +13,7 @@ public class ArrayTests
[DataRow(true)]
public void AsArrayShouldGiveLength1(object o)
{
object[] array = o.AsArray()!;
object[] array = o.AsArrayValue()!;
Assert.IsNotNull(array);
Assert.IsTrue(array.Length == 1);
}
@ -24,7 +24,7 @@ public class ArrayTests
[DataRow(true)]
public void AsArrayShouldContainObject(object o)
{
object[] array = o.AsArray()!;
object[] array = o.AsArrayValue()!;
Assert.IsNotNull(array);
Assert.AreEqual(o, array[0]);
}

View File

@ -9,18 +9,18 @@ public class CoreTests
[TestMethod]
public void AsArrayShouldBeLength1()
{
Assert.AreEqual(1, 0.AsArray().Length);
Assert.AreEqual(1, string.Empty.AsArray().Length);
Assert.AreEqual(1, true.AsArray().Length);
Assert.AreEqual(1, ((object?)null).AsArray().Length);
Assert.AreEqual(1, 0.AsArrayValue().Length);
Assert.AreEqual(1, string.Empty.AsArrayValue().Length);
Assert.AreEqual(1, true.AsArrayValue().Length);
Assert.AreEqual(1, ((object?)null).AsArrayValue().Length);
}
[TestMethod]
public void AsEnumerableShouldBeLength1()
{
Assert.AreEqual(1, 0.AsEnumerable().Count());
Assert.AreEqual(1, string.Empty.AsEnumerable().Count());
Assert.AreEqual(1, true.AsEnumerable().Count());
Assert.AreEqual(1, ((object?)null).AsEnumerable().Count());
Assert.AreEqual(1, 0.AsEnumerableValue().Count());
Assert.AreEqual(1, string.Empty.AsEnumerableValue().Count());
Assert.AreEqual(1, true.AsEnumerableValue().Count());
Assert.AreEqual(1, ((object?)null).AsEnumerableValue().Count());
}
}

View File

@ -12,7 +12,7 @@ public class EnumerableTests
[DataRow(true)]
public void AsEnumerable_ShouldWrapElement_GivenValue(object o)
{
IEnumerable<object?> array = o.AsEnumerable().ToArray(); // prevent multiple enumeration of IEnumerable
IEnumerable<object?> array = o.AsEnumerableValue().ToArray(); // prevent multiple enumeration of IEnumerable
Assert.IsNotNull(array);
Assert.IsTrue(array.Count() == 1);
Assert.AreEqual(o, array.ElementAt(0));

View File

@ -1,4 +1,4 @@
namespace X10D.Core;
namespace X10D.Core;
/// <summary>
/// Extension methods which apply to all types.
@ -9,11 +9,11 @@ public static class Extensions
/// Returns an array containing the specified value.
/// </summary>
/// <param name="value">The value to encapsulate.</param>
/// <typeparam name="T">The value type.</typeparam>
/// <typeparam name="T">The type of <paramref name="value"/>.</typeparam>
/// <returns>
/// An array of type <typeparamref name="T" /> with length 1, whose only element is <paramref name="value" />.
/// </returns>
public static T?[] AsArray<T>(this T? value)
public static T?[] AsArrayValue<T>(this T? value)
{
return new[] {value};
}
@ -22,11 +22,11 @@ public static class Extensions
/// Returns an enumerable collection containing the specified value.
/// </summary>
/// <param name="value">The value to encapsulate.</param>
/// <typeparam name="T">The value type.</typeparam>
/// <typeparam name="T">The type of <paramref name="value"/>.</typeparam>
/// <returns>
/// An enumerable collection of type <typeparamref name="T" />, whose only element is <paramref name="value" />.
/// </returns>
public static IEnumerable<T?> AsEnumerable<T>(this T? value)
public static IEnumerable<T?> AsEnumerableValue<T>(this T? value)
{
yield return value;
}