first commit
This commit is contained in:
46
Core/Extensions/SystemIOStreamExtensions.cs
Normal file
46
Core/Extensions/SystemIOStreamExtensions.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
namespace Just.Core.Extensions;
|
||||
|
||||
public static class SystemIOStreamExtensions
|
||||
{
|
||||
public static void Populate(this Stream stream, byte[] buffer, int offset, int length)
|
||||
=> stream.Populate(buffer.AsSpan(offset, length));
|
||||
public static void Populate(this Stream stream, byte[] buffer)
|
||||
=> stream.Populate(buffer.AsSpan());
|
||||
public static void Populate(this Stream stream, Span<byte> buffer)
|
||||
{
|
||||
do
|
||||
{
|
||||
var readed = stream.Read(buffer);
|
||||
|
||||
if (readed == 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
}
|
||||
|
||||
buffer = buffer[readed..];
|
||||
}
|
||||
while (buffer.Length > 0);
|
||||
}
|
||||
|
||||
public static async ValueTask PopulateAsync(this Stream stream, byte[] buffer, CancellationToken cancellationToken = default)
|
||||
=> await stream.PopulateAsync(buffer.AsMemory(), cancellationToken);
|
||||
public static async ValueTask PopulateAsync(this Stream stream, byte[] buffer, int offset, int length, CancellationToken cancellationToken = default)
|
||||
=> await stream.PopulateAsync(buffer.AsMemory(offset, length), cancellationToken);
|
||||
public static async ValueTask PopulateAsync(this Stream stream, Memory<byte> buffer, CancellationToken cancellationToken = default)
|
||||
{
|
||||
do
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var readed = await stream.ReadAsync(buffer, cancellationToken);
|
||||
|
||||
if (readed == 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
}
|
||||
|
||||
buffer = buffer[readed..];
|
||||
}
|
||||
while (buffer.Length > 0);
|
||||
}
|
||||
}
|
||||
36
Core/Extensions/SystemStringExtensions.cs
Normal file
36
Core/Extensions/SystemStringExtensions.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
namespace Just.Core.Extensions;
|
||||
|
||||
public static class SystemStringExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates whether the specified string is null or an empty string ("").
|
||||
/// </summary>
|
||||
/// <param name="str">The string to test.</param>
|
||||
/// <returns>true if the value parameter is null or an empty string (""); otherwise, false.</returns>
|
||||
public static bool IsNullOrEmpty([NotNullWhen(false)] this string? str) => string.IsNullOrEmpty(str);
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether a specified string is null, empty, or consists only of white-space
|
||||
/// characters.
|
||||
/// </summary>
|
||||
/// <param name="str">The string to test.</param>
|
||||
/// <returns>true if the value parameter is null or <see cref="System.String.Empty"/>, or if value consists
|
||||
/// exclusively of white-space characters.</returns>
|
||||
public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? str) => string.IsNullOrWhiteSpace(str);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the specified string contains any characters.
|
||||
/// </summary>
|
||||
/// <param name="str">The string to test.</param>
|
||||
/// <returns>true if the value parameter contains any characters; otherwise, false.</returns>
|
||||
public static bool IsNotNullOrEmpty([NotNullWhen(true)] this string? str) => !string.IsNullOrEmpty(str);
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether a specified string contains non white-space characters.
|
||||
/// </summary>
|
||||
/// <param name="str">The string to test.</param>
|
||||
/// <returns>true if the value parameter contains non white-space characters; otherwise, false.</returns>
|
||||
public static bool IsNotNullOrWhiteSpace([NotNullWhen(true)] this string? str) => !string.IsNullOrWhiteSpace(str);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user