-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Net
Milestone
Description
Background and motivation
Uri.ToString() is a common source of allocation, especially in logging code. We can avoid some such allocation by enabling Uri to play nicely with string interpolation by implementing ISpanFormattable that enables it to write directly into a destination buffer.
API Proposal
namespace System;
public class Uri : ISerializable,
+ ISpanFormattable
{
+ bool TryFormat(Span<char> destination, out int charsWritten);
}API Usage
StringBuilder sb = ...;
sb.Append($"Url: {url}");Alternative Designs
- We could also implement
IUtf8SpanFormattableto support directly writing out UTF8 bytes.
Risks
No response
ShreyasJejurkar, wfurt, PaulusParssinen, Wraith2, Tornhoof and 1 more
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Net