Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update StringExtensions and add RangeExtensions. Update libraries #199

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/TinyHelpers.AspNetCore/TinyHelpers.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.6.2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.7.0" />
</ItemGroup>

<ItemGroup>
Expand Down
33 changes: 33 additions & 0 deletions src/TinyHelpers/Extensions/RangeExtensions.cs
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
6 changes: 4 additions & 2 deletions src/TinyHelpers/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public static string ReplaceIgnoreCase(this string input, string pattern, string
/// <param name="defaultValue">The value to return if the string is <see langword="null"/> or contains only whitespaces.</param>
/// <returns>The actual value of this string instance, or <paramref name="defaultValue"/> if the string is <see langword="null"/> or contains only whitespaces.</returns>
[return: NotNullIfNotNull(nameof(input))]
public static string? GetValueOrDefault([NotNullIfNotNull(nameof(input))] this string? input, string? defaultValue)
[return: NotNullIfNotNull(nameof(defaultValue))]
public static string? GetValueOrDefault(this string? input, string? defaultValue)
=> input.GetValueOrDefault(defaultValue, whiteSpaceAsEmpty: true);

/// <summary>
Expand All @@ -81,7 +82,8 @@ public static string ReplaceIgnoreCase(this string input, string pattern, string
/// <param name="whiteSpaceAsEmpty"><see langword="true"/> if whitespaces must be considered as empty characters; otherwise, <see langword="false"/>.</param>
/// <returns>The actual value of this string instance, or <paramref name="defaultValue"/> if the string is <see langword="null"/> or contains only whitespaces.</returns>
[return: NotNullIfNotNull(nameof(input))]
public static string? GetValueOrDefault([NotNullIfNotNull(nameof(input))] this string? input, string? defaultValue, bool whiteSpaceAsEmpty)
[return: NotNullIfNotNull(nameof(defaultValue))]
public static string? GetValueOrDefault(this string? input, string? defaultValue, bool whiteSpaceAsEmpty)
=> whiteSpaceAsEmpty ? (string.IsNullOrWhiteSpace(input) ? defaultValue : input) : (string.IsNullOrEmpty(input) ? defaultValue : input);

/// <summary>
Expand Down
Loading