private sealed class NullTextWriter : TextWriter
{
- internal NullTextWriter()
- {
- }
+ internal NullTextWriter() { }
public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture;
-
public override Encoding Encoding => Encoding.Unicode;
- public override void Write(char[] buffer, int index, int count)
- {
- }
-
- public override void Write(string? value)
- {
- }
-
- // Not strictly necessary, but for perf reasons
- public override void WriteLine()
- {
- }
-
- // Not strictly necessary, but for perf reasons
- public override void WriteLine(string? value)
- {
- }
-
- public override void WriteLine(object? value)
- {
- }
-
- public override void Write(char value)
- {
- }
+ // To avoid all unnecessary overhead in the base, override all Flush/Write methods as pure nops.
+
+ public override void Flush() { }
+ public override Task FlushAsync() => Task.CompletedTask;
+
+ public override void Write(char value) { }
+ public override void Write(char[]? buffer) { }
+ public override void Write(char[] buffer, int index, int count) { }
+ public override void Write(ReadOnlySpan<char> buffer) { }
+ public override void Write(bool value) { }
+ public override void Write(int value) { }
+ public override void Write(uint value) { }
+ public override void Write(long value) { }
+ public override void Write(ulong value) { }
+ public override void Write(float value) { }
+ public override void Write(double value) { }
+ public override void Write(decimal value) { }
+ public override void Write(string? value) { }
+ public override void Write(object? value) { }
+ public override void Write(StringBuilder? value) { }
+ public override void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0) { }
+ public override void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1) { }
+ public override void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1, object? arg2) { }
+ public override void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[] arg) { }
+ public override Task WriteAsync(char value) => Task.CompletedTask;
+ public override Task WriteAsync(string? value) => Task.CompletedTask;
+ public override Task WriteAsync(StringBuilder? value, CancellationToken cancellationToken = default) => Task.CompletedTask;
+ public override Task WriteAsync(char[] buffer, int index, int count) => Task.CompletedTask;
+ public override Task WriteAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default) => Task.CompletedTask;
+ public override void WriteLine() { }
+ public override void WriteLine(char value) { }
+ public override void WriteLine(char[]? buffer) { }
+ public override void WriteLine(char[] buffer, int index, int count) { }
+ public override void WriteLine(ReadOnlySpan<char> buffer) { }
+ public override void WriteLine(bool value) { }
+ public override void WriteLine(int value) { }
+ public override void WriteLine(uint value) { }
+ public override void WriteLine(long value) { }
+ public override void WriteLine(ulong value) { }
+ public override void WriteLine(float value) { }
+ public override void WriteLine(double value) { }
+ public override void WriteLine(decimal value) { }
+ public override void WriteLine(string? value) { }
+ public override void WriteLine(StringBuilder? value) { }
+ public override void WriteLine(object? value) { }
+ public override void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0) { }
+ public override void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1) { }
+ public override void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1, object? arg2) { }
+ public override void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[] arg) { }
+ public override Task WriteLineAsync(char value) => Task.CompletedTask;
+ public override Task WriteLineAsync(string? value) => Task.CompletedTask;
+ public override Task WriteLineAsync(StringBuilder? value, CancellationToken cancellationToken = default) => Task.CompletedTask;
+ public override Task WriteLineAsync(char[] buffer, int index, int count) => Task.CompletedTask;
+ public override Task WriteLineAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default) => Task.CompletedTask;
+ public override Task WriteLineAsync() => Task.CompletedTask;
}
public static TextWriter Synchronized(TextWriter writer)