-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update StringExtensions and add RangeExtensions. Update libraries (#199)
- Loading branch information
Showing
4 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace TinyHelpers.Extensions; | ||
|
||
#if NET6_0_OR_GREATER | ||
/// <summary> | ||
/// Contains extension methods for the <see cref="Range"/> type. | ||
/// </summary> | ||
/// <seealso cref="Range"/> | ||
public static class RangeExtensions | ||
{ | ||
/// <summary> | ||
/// Returns an enumerator that iterates through the range of integers defined by the specified <see cref="Range"/>. | ||
/// </summary> | ||
/// <param name="range">The range of integers to iterate over.</param> | ||
/// <returns>An enumerator that can be used to iterate through the range of integers.</returns> | ||
public static IEnumerator<int> GetEnumerator(this Range range) | ||
{ | ||
if (range.Start.IsFromEnd || range.Start.Value >= range.End.Value) | ||
{ | ||
for (var i = range.Start.Value; i >= range.End.Value; i--) | ||
{ | ||
yield return i; | ||
} | ||
} | ||
else | ||
{ | ||
for (var i = range.Start.Value; i <= range.End.Value; i++) | ||
{ | ||
yield return i; | ||
} | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters