Skip to content

Commit

Permalink
Add Console.Write{Line} span overloads (dotnet#105531)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored Aug 15, 2024
1 parent cef3898 commit 9ea7e1a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/libraries/System.Console/ref/System.Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public static void Write(long value) { }
public static void Write(object? value) { }
public static void Write(float value) { }
public static void Write(string? value) { }
public static void Write(System.ReadOnlySpan<char> value) { }
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0) { }
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1) { }
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1, object? arg2) { }
Expand All @@ -181,6 +182,7 @@ public static void WriteLine(long value) { }
public static void WriteLine(object? value) { }
public static void WriteLine(float value) { }
public static void WriteLine(string? value) { }
public static void WriteLine(ReadOnlySpan<char> value) { }
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0) { }
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1) { }
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1, object? arg2) { }
Expand Down
12 changes: 12 additions & 0 deletions src/libraries/System.Console/src/System/Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,12 @@ public static void WriteLine(string? value)
Out.WriteLine(value);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void WriteLine(ReadOnlySpan<char> value)
{
Out.WriteLine(value);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0)
{
Expand Down Expand Up @@ -969,6 +975,12 @@ public static void Write(string? value)
Out.Write(value);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void Write(ReadOnlySpan<char> value)
{
Out.Write(value);
}

private static void HandlePosixSignal(PosixSignalContext ctx)
{
Debug.Assert(ctx.Signal == PosixSignal.SIGINT || ctx.Signal == PosixSignal.SIGQUIT);
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/System.Console/tests/ReadAndWrite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private static void WriteCore()
Console.Write(50UL);
Console.Write(new object());
Console.Write("Hello World");
Console.Write("Hello World".AsSpan());
}

private static void WriteLineCore()
Expand Down Expand Up @@ -145,6 +146,7 @@ private static void WriteLineCore()
Console.WriteLine(50UL);
Console.WriteLine(new object());
Console.WriteLine("Hello World");
Console.WriteLine("Hello World".AsSpan());
}

[Fact]
Expand Down Expand Up @@ -187,6 +189,7 @@ public static async Task OutWriteAndWriteLineOverloads()
writer.Write(50UL);
writer.Write(new object());
writer.Write("Hello World");
writer.Write("Hello World".AsSpan());

writer.Flush();

Expand Down

0 comments on commit 9ea7e1a

Please sign in to comment.