mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-22 13:48:47 +00:00
style: move Write/WriteLine overloads to files
This change should help to organise this entire class a bit better, due to the number of overloads that exist.
This commit is contained in:
parent
e6025b1a4c
commit
f13907a4d0
83
X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Int32.cs
Normal file
83
X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Int32.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
||||
public static partial class TextWriterExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte signed integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, int value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, int value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteLineNoAlloc(writer, (long)value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, int value, ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteNoAlloc(value, format, formatProvider);
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
85
X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Int64.cs
Normal file
85
X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.Int64.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
||||
public static partial class TextWriterExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the text representation of an 8-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte signed integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, long value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of an 8-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, long value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of an 8-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteLineNoAlloc(this TextWriter writer,
|
||||
long value,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteNoAlloc(value, format, formatProvider);
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
88
X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.UInt32.cs
Normal file
88
X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.UInt32.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
||||
public static partial class TextWriterExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte unsigned integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte unsigned integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, uint value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte unsigned integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, uint value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteLineNoAlloc(writer, (long)value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte unsigned integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteLineNoAlloc(this TextWriter writer,
|
||||
uint value,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteNoAlloc(value, format, formatProvider);
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
88
X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.UInt64.cs
Normal file
88
X10D/src/IO/TextWriterExtensions.WriteLineNoAlloc.UInt64.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
||||
public static partial class TextWriterExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the text representation of an 8-byte unsigned integer to the text stream, followed by a line terminator,
|
||||
/// without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte unsigned integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, ulong value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of an 8-byte unsigned integer to the text stream, followed by a line terminator,
|
||||
/// without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, ulong value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of an 8-byte unsigned integer to the text stream, followed by a line terminator,
|
||||
/// without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteLineNoAlloc(this TextWriter writer,
|
||||
ulong value,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteNoAlloc(value, format, formatProvider);
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
92
X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Int32.cs
Normal file
92
X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Int32.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using System.Globalization;
|
||||
using X10D.Math;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
||||
public static partial class TextWriterExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte signed integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteNoAlloc(this TextWriter writer, int value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteNoAlloc(this TextWriter writer, int value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteNoAlloc(this TextWriter writer, int value, ReadOnlySpan<char> format, IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
int digitCount = value.CountDigits();
|
||||
Span<char> buffer = stackalloc char[System.Math.Max(value < 0 ? digitCount + 1 : digitCount, 100)];
|
||||
if (value.TryFormat(buffer, out int charsWritten, format, formatProvider))
|
||||
{
|
||||
Span<char> truncated = buffer[..charsWritten];
|
||||
for (var index = 0; index < truncated.Length; index++)
|
||||
{
|
||||
writer.Write(truncated[index]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(value.ToString(format.ToString(), formatProvider));
|
||||
}
|
||||
}
|
||||
}
|
95
X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Int64.cs
Normal file
95
X10D/src/IO/TextWriterExtensions.WriteNoAlloc.Int64.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System.Globalization;
|
||||
using X10D.Math;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
||||
public static partial class TextWriterExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the text representation of an 8-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte signed integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteNoAlloc(this TextWriter writer, long value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of an 8-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteNoAlloc(this TextWriter writer, long value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of an 8-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteNoAlloc(this TextWriter writer,
|
||||
long value,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
int digitCount = value.CountDigits();
|
||||
Span<char> buffer = stackalloc char[System.Math.Max(value < 0 ? digitCount + 1 : digitCount, 100)];
|
||||
if (value.TryFormat(buffer, out int charsWritten, format, formatProvider))
|
||||
{
|
||||
Span<char> truncated = buffer[..charsWritten];
|
||||
for (var index = 0; index < truncated.Length; index++)
|
||||
{
|
||||
writer.Write(truncated[index]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(value.ToString(format.ToString(), formatProvider));
|
||||
}
|
||||
}
|
||||
}
|
98
X10D/src/IO/TextWriterExtensions.WriteNoAlloc.UInt32.cs
Normal file
98
X10D/src/IO/TextWriterExtensions.WriteNoAlloc.UInt32.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using System.Globalization;
|
||||
using X10D.Math;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
||||
public static partial class TextWriterExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte unsigned integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte unsigned integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteNoAlloc(this TextWriter writer, uint value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte unsigned integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteNoAlloc(this TextWriter writer, uint value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte unsigned integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteNoAlloc(this TextWriter writer,
|
||||
uint value,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
int digitCount = value.CountDigits();
|
||||
Span<char> buffer = stackalloc char[System.Math.Max(digitCount, 100)];
|
||||
if (value.TryFormat(buffer, out int charsWritten, format, formatProvider))
|
||||
{
|
||||
Span<char> truncated = buffer[..charsWritten];
|
||||
for (var index = 0; index < truncated.Length; index++)
|
||||
{
|
||||
writer.Write(truncated[index]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(value.ToString(format.ToString(), formatProvider));
|
||||
}
|
||||
}
|
||||
}
|
98
X10D/src/IO/TextWriterExtensions.WriteNoAlloc.UInt64.cs
Normal file
98
X10D/src/IO/TextWriterExtensions.WriteNoAlloc.UInt64.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using System.Globalization;
|
||||
using X10D.Math;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
||||
public static partial class TextWriterExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the text representation of an 8-byte unsigned integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte unsigned integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteNoAlloc(this TextWriter writer, ulong value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of an 8-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteNoAlloc(this TextWriter writer, ulong value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of an 8-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteNoAlloc(this TextWriter writer,
|
||||
ulong value,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
int digitCount = value.CountDigits();
|
||||
Span<char> buffer = stackalloc char[System.Math.Max(digitCount, 100)];
|
||||
if (value.TryFormat(buffer, out int charsWritten, format, formatProvider))
|
||||
{
|
||||
Span<char> truncated = buffer[..charsWritten];
|
||||
for (var index = 0; index < truncated.Length; index++)
|
||||
{
|
||||
writer.Write(truncated[index]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(value.ToString(format.ToString(), formatProvider));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,685 +1,8 @@
|
||||
using System.Globalization;
|
||||
using X10D.Math;
|
||||
|
||||
namespace X10D.IO;
|
||||
namespace X10D.IO;
|
||||
|
||||
/// <summary>
|
||||
/// IO-related extension methods for <see cref="TextWriter" />.
|
||||
/// </summary>
|
||||
public static class TextWriterExtensions
|
||||
public static partial class TextWriterExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte signed integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteNoAlloc(this TextWriter writer, int value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteNoAlloc(this TextWriter writer, int value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteNoAlloc(this TextWriter writer, int value, ReadOnlySpan<char> format, IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
int digitCount = value.CountDigits();
|
||||
Span<char> buffer = stackalloc char[System.Math.Max(value < 0 ? digitCount + 1 : digitCount, 1000)];
|
||||
if (value.TryFormat(buffer, out int charsWritten, format, formatProvider))
|
||||
{
|
||||
Span<char> truncated = buffer[..charsWritten];
|
||||
for (var index = 0; index < truncated.Length; index++)
|
||||
{
|
||||
writer.Write(truncated[index]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(value.ToString(format.ToString(), formatProvider));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte unsigned integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte unsigned integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteNoAlloc(this TextWriter writer, uint value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte unsigned integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteNoAlloc(this TextWriter writer, uint value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte unsigned integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteNoAlloc(this TextWriter writer,
|
||||
uint value,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
int digitCount = value.CountDigits();
|
||||
Span<char> buffer = stackalloc char[System.Math.Max(digitCount, 1000)];
|
||||
if (value.TryFormat(buffer, out int charsWritten, format, formatProvider))
|
||||
{
|
||||
Span<char> truncated = buffer[..charsWritten];
|
||||
for (var index = 0; index < truncated.Length; index++)
|
||||
{
|
||||
writer.Write(truncated[index]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(value.ToString(format.ToString(), formatProvider));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 8-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte signed integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteNoAlloc(this TextWriter writer, long value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 8-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteNoAlloc(this TextWriter writer, long value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 8-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteNoAlloc(this TextWriter writer,
|
||||
long value,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
int digitCount = value.CountDigits();
|
||||
Span<char> buffer = stackalloc char[System.Math.Max(value < 0 ? digitCount + 1 : digitCount, 1000)];
|
||||
if (value.TryFormat(buffer, out int charsWritten, format, formatProvider))
|
||||
{
|
||||
Span<char> truncated = buffer[..charsWritten];
|
||||
for (var index = 0; index < truncated.Length; index++)
|
||||
{
|
||||
writer.Write(truncated[index]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(value.ToString(format.ToString(), formatProvider));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 8-byte unsigned integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte unsigned integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteNoAlloc(this TextWriter writer, ulong value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 8-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteNoAlloc(this TextWriter writer, ulong value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
WriteNoAlloc(writer, value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 8-byte signed integer to the text stream, without allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteNoAlloc(this TextWriter writer,
|
||||
ulong value,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
int digitCount = value.CountDigits();
|
||||
Span<char> buffer = stackalloc char[System.Math.Max(digitCount, 1000)];
|
||||
if (value.TryFormat(buffer, out int charsWritten, format, formatProvider))
|
||||
{
|
||||
Span<char> truncated = buffer[..charsWritten];
|
||||
for (var index = 0; index < truncated.Length; index++)
|
||||
{
|
||||
writer.Write(truncated[index]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(value.ToString(format.ToString(), formatProvider));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte signed integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, int value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, int value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, int value, ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteNoAlloc(value, format, formatProvider);
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte unsigned integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte unsigned integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, uint value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte unsigned integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, uint value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 4-byte unsigned integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 4-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteLineNoAlloc(this TextWriter writer,
|
||||
uint value,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteNoAlloc(value, format, formatProvider);
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 8-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte signed integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, long value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 8-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, long value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 8-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte signed integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
public static void WriteLineNoAlloc(this TextWriter writer,
|
||||
long value,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteNoAlloc(value, format, formatProvider);
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 8-byte unsigned integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte unsigned integer to write.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, ulong value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, "N0".AsSpan(), CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 8-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteLineNoAlloc(this TextWriter writer, ulong value, ReadOnlySpan<char> format)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteLineNoAlloc(value, format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the text representation of a 8-byte signed integer to the text stream, followed by a line terminator, without
|
||||
/// allocating a string.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> to write to.</param>
|
||||
/// <param name="value">The 8-byte unsigned integer to write.</param>
|
||||
/// <param name="format">A standard or custom numeric format string.</param>
|
||||
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <remarks>This method may still allocate if the integer is too large to fit in a stack-allocated buffer.</remarks>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="writer" /> is <see langword="null" />.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The <see cref="TextWriter" /> is closed.</exception>
|
||||
/// <exception cref="IOException">An I/O error occurs.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static void WriteLineNoAlloc(this TextWriter writer,
|
||||
ulong value,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? formatProvider)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(writer);
|
||||
#else
|
||||
if (writer is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
#endif
|
||||
|
||||
writer.WriteNoAlloc(value, format, formatProvider);
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user