From f7f3ea71bbc57d13e39b745bff85444b0cb42a5b Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 26 Apr 2022 10:45:18 +0100 Subject: [PATCH] Append "Value" to AsArray/AsEnumerable, to reduce risk of LINQ collision --- X10D.Tests/src/Collections/ArrayTests.cs | 4 ++-- X10D.Tests/src/Core/CoreTests.cs | 16 ++++++++-------- X10D.Tests/src/Core/EnumerableTests.cs | 2 +- X10D/src/Core/Extensions.cs | 10 +++++----- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/X10D.Tests/src/Collections/ArrayTests.cs b/X10D.Tests/src/Collections/ArrayTests.cs index 29c6472..02784f4 100644 --- a/X10D.Tests/src/Collections/ArrayTests.cs +++ b/X10D.Tests/src/Collections/ArrayTests.cs @@ -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]); } diff --git a/X10D.Tests/src/Core/CoreTests.cs b/X10D.Tests/src/Core/CoreTests.cs index 35e9f53..0084c43 100644 --- a/X10D.Tests/src/Core/CoreTests.cs +++ b/X10D.Tests/src/Core/CoreTests.cs @@ -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()); } } diff --git a/X10D.Tests/src/Core/EnumerableTests.cs b/X10D.Tests/src/Core/EnumerableTests.cs index d3b4341..5b6deba 100644 --- a/X10D.Tests/src/Core/EnumerableTests.cs +++ b/X10D.Tests/src/Core/EnumerableTests.cs @@ -12,7 +12,7 @@ public class EnumerableTests [DataRow(true)] public void AsEnumerable_ShouldWrapElement_GivenValue(object o) { - IEnumerable array = o.AsEnumerable().ToArray(); // prevent multiple enumeration of IEnumerable + IEnumerable array = o.AsEnumerableValue().ToArray(); // prevent multiple enumeration of IEnumerable Assert.IsNotNull(array); Assert.IsTrue(array.Count() == 1); Assert.AreEqual(o, array.ElementAt(0)); diff --git a/X10D/src/Core/Extensions.cs b/X10D/src/Core/Extensions.cs index ff51a8a..0dec423 100644 --- a/X10D/src/Core/Extensions.cs +++ b/X10D/src/Core/Extensions.cs @@ -1,4 +1,4 @@ -namespace X10D.Core; +namespace X10D.Core; /// /// Extension methods which apply to all types. @@ -9,11 +9,11 @@ public static class Extensions /// Returns an array containing the specified value. /// /// The value to encapsulate. - /// The value type. + /// The type of . /// /// An array of type with length 1, whose only element is . /// - public static T?[] AsArray(this T? value) + public static T?[] AsArrayValue(this T? value) { return new[] {value}; } @@ -22,11 +22,11 @@ public static class Extensions /// Returns an enumerable collection containing the specified value. /// /// The value to encapsulate. - /// The value type. + /// The type of . /// /// An enumerable collection of type , whose only element is . /// - public static IEnumerable AsEnumerable(this T? value) + public static IEnumerable AsEnumerableValue(this T? value) { yield return value; }