diff --git a/X10D/src/Int16Extensions/Int16Extensions.cs b/X10D/src/Int16Extensions/Int16Extensions.cs index 1c93055..b294b55 100644 --- a/X10D/src/Int16Extensions/Int16Extensions.cs +++ b/X10D/src/Int16Extensions/Int16Extensions.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.Contracts; +using System.Diagnostics.Contracts; using System.Net; using System.Runtime.CompilerServices; @@ -213,6 +213,86 @@ public static class Int16Extensions return Math.Sign(value); } + /// + /// Returns an enumerable collection of 16-bit signed integers that range from the current value to a specified value. + /// + /// The value of the first integer in the sequence. + /// The value of the last integer in the sequence. + /// + /// + /// An enumerable collection of 16-bit signed integers that range from to + /// in ascending order if is less than than . + /// + /// -or- + /// + /// An enumerable collection of 16-bit signed integers that range from to + /// in descending order if is greater than than + /// . + /// + /// -or- + /// + /// An enumerable collection that contains a single value if is equal to + /// . + /// + /// + public static IEnumerable To(this short start, short end) + { + return start.To(end, 1); + } + + /// + /// Returns an enumerable collection of 16-bit signed integers that range from the current value to a specified value. + /// + /// The value of the first integer in the sequence. + /// The value of the last integer in the sequence. + /// The increment by which to step. + /// + /// + /// An enumerable collection of 16-bit signed integers that range from to + /// in ascending order if is less than than . + /// + /// -or- + /// + /// An enumerable collection of 16-bit signed integers that range from to + /// in descending order if is greater than than + /// . + /// + /// -or- + /// + /// An enumerable collection that contains a single value if is equal to + /// . + /// + /// + public static IEnumerable To(this short start, short end, short step) + { + if (step == 0) + { + throw new ArgumentOutOfRangeException(nameof(step), "Step cannot be zero."); + } + + if (end == start) + { + yield return start; + yield break; + } + + if (step > 0 || start < end) + { + for (short i = start; i <= end; i += step) + { + yield return i; + } + } + else + { + short absStep = Math.Abs(step); + for (short i = start; i >= end; i -= absStep) + { + yield return i; + } + } + } + /// /// Converts an integer value from network byte order to host byte order. /// diff --git a/X10D/src/Int32Extensions/Int32Extensions.cs b/X10D/src/Int32Extensions/Int32Extensions.cs index f7ae159..b56ef1f 100644 --- a/X10D/src/Int32Extensions/Int32Extensions.cs +++ b/X10D/src/Int32Extensions/Int32Extensions.cs @@ -277,6 +277,86 @@ public static class Int32Extensions return Math.Sign(value); } + /// + /// Returns an enumerable collection of 32-bit signed integers that range from the current value to a specified value. + /// + /// The value of the first integer in the sequence. + /// The value of the last integer in the sequence. + /// + /// + /// An enumerable collection of 32-bit signed integers that range from to + /// in ascending order if is less than than . + /// + /// -or- + /// + /// An enumerable collection of 32-bit signed integers that range from to + /// in descending order if is greater than than + /// . + /// + /// -or- + /// + /// An enumerable collection that contains a single value if is equal to + /// . + /// + /// + public static IEnumerable To(this int start, int end) + { + return start.To(end, 1); + } + + /// + /// Returns an enumerable collection of 32-bit signed integers that range from the current value to a specified value. + /// + /// The value of the first integer in the sequence. + /// The value of the last integer in the sequence. + /// The increment by which to step. + /// + /// + /// An enumerable collection of 32-bit signed integers that range from to + /// in ascending order if is less than than . + /// + /// -or- + /// + /// An enumerable collection of 32-bit signed integers that range from to + /// in descending order if is greater than than + /// . + /// + /// -or- + /// + /// An enumerable collection that contains a single value if is equal to + /// . + /// + /// + public static IEnumerable To(this int start, int end, int step) + { + if (step == 0) + { + throw new ArgumentOutOfRangeException(nameof(step), "Step cannot be zero."); + } + + if (end == start) + { + yield return start; + yield break; + } + + if (step > 0 || start < end) + { + for (int i = start; i <= end; i += step) + { + yield return i; + } + } + else + { + int absStep = Math.Abs(step); + for (int i = start; i >= end; i -= absStep) + { + yield return i; + } + } + } + /// /// Converts an integer value from network byte order to host byte order. /// diff --git a/X10D/src/Int64Extensions/Int64Extensions.cs b/X10D/src/Int64Extensions/Int64Extensions.cs index f523be8..affb235 100644 --- a/X10D/src/Int64Extensions/Int64Extensions.cs +++ b/X10D/src/Int64Extensions/Int64Extensions.cs @@ -238,6 +238,86 @@ public static class Int64Extensions return Math.Sign(value); } + /// + /// Returns an enumerable collection of 64-bit signed integers that range from the current value to a specified value. + /// + /// The value of the first integer in the sequence. + /// The value of the last integer in the sequence. + /// + /// + /// An enumerable collection of 64-bit signed integers that range from to + /// in ascending order if is less than than . + /// + /// -or- + /// + /// An enumerable collection of 64-bit signed integers that range from to + /// in descending order if is greater than than + /// . + /// + /// -or- + /// + /// An enumerable collection that contains a single value if is equal to + /// . + /// + /// + public static IEnumerable To(this long start, long end) + { + return start.To(end, 1); + } + + /// + /// Returns an enumerable collection of 64-bit signed integers that range from the current value to a specified value. + /// + /// The value of the first integer in the sequence. + /// The value of the last integer in the sequence. + /// The increment by which to step. + /// + /// + /// An enumerable collection of 64-bit signed integers that range from to + /// in ascending order if is less than than . + /// + /// -or- + /// + /// An enumerable collection of 64-bit signed integers that range from to + /// in descending order if is greater than than + /// . + /// + /// -or- + /// + /// An enumerable collection that contains a single value if is equal to + /// . + /// + /// + public static IEnumerable To(this long start, long end, long step) + { + if (step == 0) + { + throw new ArgumentOutOfRangeException(nameof(step), "Step cannot be zero."); + } + + if (end == start) + { + yield return start; + yield break; + } + + if (step > 0 || start < end) + { + for (long i = start; i <= end; i += step) + { + yield return i; + } + } + else + { + long absStep = Math.Abs(step); + for (long i = start; i >= end; i -= absStep) + { + yield return i; + } + } + } + /// /// Converts an integer value from network byte order to host byte order. ///