diff --git a/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs b/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs index 2db1c8397243d..8035810b1f16d 100644 --- a/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs +++ b/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs @@ -265,6 +265,7 @@ public IPAddress(System.ReadOnlySpan address, long scopeid) { } public override string ToString() { throw null; } string IFormattable.ToString(string? format, IFormatProvider? formatProvider) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten) { throw null; } bool ISpanFormattable.TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) { throw null; } bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } public static bool TryParse(System.ReadOnlySpan ipSpan, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Net.IPAddress? address) { throw null; } @@ -316,6 +317,7 @@ public IPEndPoint(System.Net.IPAddress address, int port) { } static bool System.ISpanParsable.TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.Net.IPNetwork result) { throw null; } public override string ToString() { throw null; } public bool TryFormat(System.Span destination, out int charsWritten) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out System.Net.IPNetwork result) { throw null; } public static bool TryParse(string? s, out System.Net.IPNetwork result) { throw null; } } diff --git a/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs b/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs index cf2a603a24b38..899f1885d3c0e 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs @@ -427,6 +427,13 @@ string IFormattable.ToString(string? format, IFormatProvider? formatProvider) => public bool TryFormat(Span destination, out int charsWritten) => TryFormatCore(destination, out charsWritten); + /// Tries to format the current IP address into the provided span. + /// When this method returns, the IP address as a span of UTF8 bytes. + /// When this method returns, the number of bytes written into the . + /// if the formatting was successful; otherwise, . + public bool TryFormat(Span utf8Destination, out int bytesWritten) => + TryFormatCore(utf8Destination, out bytesWritten); + /// bool ISpanFormattable.TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) => // format and provider are explicitly ignored diff --git a/src/libraries/System.Net.Primitives/src/System/Net/IPNetwork.cs b/src/libraries/System.Net.Primitives/src/System/Net/IPNetwork.cs index a667a8a3de87f..b3c94569148aa 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/IPNetwork.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/IPNetwork.cs @@ -251,6 +251,15 @@ public override string ToString() => public bool TryFormat(Span destination, out int charsWritten) => destination.TryWrite(CultureInfo.InvariantCulture, $"{BaseAddress}/{(uint)PrefixLength}", out charsWritten); + /// + /// Attempts to write the 's CIDR notation to the given UTF8 span and returns a value indicating whether the operation succeeded. + /// + /// The destination span of UTF8 bytes. + /// When this method returns, contains the number of bytes that were written to . + /// if the formatting was succesful; otherwise . + public bool TryFormat(Span utf8Destination, out int bytesWritten) => + Utf8.TryWrite(utf8Destination, CultureInfo.InvariantCulture, $"{BaseAddress}/{(uint)PrefixLength}", out bytesWritten); + /// /// Determines whether two instances are equal. /// @@ -298,11 +307,13 @@ obj is IPNetwork other && /// bool ISpanFormattable.TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) => + // format and provider are ignored TryFormat(destination, out charsWritten); /// bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) => - Utf8.TryWrite(utf8Destination, CultureInfo.InvariantCulture, $"{BaseAddress}/{(uint)PrefixLength}", out bytesWritten); + // format and provider are ignored + TryFormat(utf8Destination, out bytesWritten); /// static IPNetwork IParsable.Parse([NotNull] string s, IFormatProvider? provider) => Parse(s); diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPAddressParsing.cs b/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPAddressParsing.cs index 92b1fd3df8ead..db786a5d11dcd 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPAddressParsing.cs +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPAddressParsing.cs @@ -38,7 +38,7 @@ public class IPAddressParsingFormatting_Span : IPAddressParsingFormatting public override IPAddress Parse(string ipString) => IPAddress.Parse(ipString.AsSpan()); public override bool TryParse(string ipString, out IPAddress address) => IPAddress.TryParse(ipString.AsSpan(), out address); public virtual bool TryFormat(IPAddress address, Span destination, out int charsWritten) => address.TryFormat(destination, out charsWritten); - public virtual bool TryFormat(IPAddress address, Span utf8Destination, out int bytesWritten) => ((IUtf8SpanFormattable)address).TryFormat(utf8Destination, out bytesWritten, default, null); + public virtual bool TryFormat(IPAddress address, Span utf8Destination, out int bytesWritten) => address.TryFormat(utf8Destination, out bytesWritten); [Theory] [MemberData(nameof(ValidIpv4Addresses))] diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPNetworkTest.cs b/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPNetworkTest.cs index c4371cf0cf2f9..6688b7a786434 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPNetworkTest.cs +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPNetworkTest.cs @@ -266,7 +266,7 @@ public void TryFormatSpan_NotEnoughLength_ReturnsFalse(string input) // UTF8 { Span span = stackalloc byte[input.Length - 1]; - Assert.False(((IUtf8SpanFormattable)network).TryFormat(span, out int bytesWritten, default, null)); + Assert.False(network.TryFormat(span, out int bytesWritten)); Assert.Equal(0, bytesWritten); } } @@ -290,7 +290,7 @@ public void TryFormatSpan_EnoughLength_Succeeds(string input) // UTF8 { Span span = stackalloc byte[input.Length + additionalLength]; - Assert.True(((IUtf8SpanFormattable)network).TryFormat(span, out int bytesWritten, default, null)); + Assert.True(network.TryFormat(span, out int bytesWritten)); Assert.Equal(input.Length, bytesWritten); Assert.Equal(input, Encoding.UTF8.GetString(span.Slice(0, bytesWritten))); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.L.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.L.cs index 50d7bc23fd3d5..679f9613fba85 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.L.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.L.cs @@ -17,7 +17,7 @@ public static partial class Utf8Formatter // private static bool TryFormatDateTimeL(DateTime value, Span destination, out int bytesWritten) { - if (((IUtf8SpanFormattable)value).TryFormat(destination, out bytesWritten, "r", CultureInfo.InvariantCulture)) + if (value.TryFormat(destination, out bytesWritten, "r", CultureInfo.InvariantCulture)) { Debug.Assert(bytesWritten == 29); Ascii.ToLowerInPlace(destination.Slice(0, bytesWritten), out bytesWritten); diff --git a/src/libraries/System.Private.CoreLib/src/System/Byte.cs b/src/libraries/System.Private.CoreLib/src/System/Byte.cs index ab924f1e4b55a..e90fb025a1b67 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Byte.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Byte.cs @@ -211,8 +211,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatUInt32(m_value, format, provider, destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatUInt32(m_value, format, provider, utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Char.cs b/src/libraries/System.Private.CoreLib/src/System/Char.cs index 643574b8fbfb1..7d0c8dc2e7d3e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Char.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Char.cs @@ -193,6 +193,7 @@ bool ISpanFormattable.TryFormat(Span destination, out int charsWritten, Re return false; } + /// bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) => new Rune(this).TryEncodeToUtf8(utf8Destination, out bytesWritten); diff --git a/src/libraries/System.Private.CoreLib/src/System/DateOnly.cs b/src/libraries/System.Private.CoreLib/src/System/DateOnly.cs index a515a66f8ae97..3dbd64024a912 100644 --- a/src/libraries/System.Private.CoreLib/src/System/DateOnly.cs +++ b/src/libraries/System.Private.CoreLib/src/System/DateOnly.cs @@ -784,10 +784,11 @@ public string ToString([StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] stri /// A span containing the characters that represent a standard or custom format string that defines the acceptable format for destination. /// An optional object that supplies culture-specific formatting information for destination. /// true if the formatting was successful; otherwise, false. - public bool TryFormat(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] ReadOnlySpan format = default(ReadOnlySpan), IFormatProvider? provider = null) => + public bool TryFormat(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) => TryFormatCore(destination, out charsWritten, format, provider); - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] ReadOnlySpan format, IFormatProvider? provider) => + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) => TryFormatCore(utf8Destination, out bytesWritten, format, provider); private bool TryFormatCore(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] ReadOnlySpan format, IFormatProvider? provider = null) diff --git a/src/libraries/System.Private.CoreLib/src/System/DateTime.cs b/src/libraries/System.Private.CoreLib/src/System/DateTime.cs index 8cfa1b480ec62..a17912657ecbb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/DateTime.cs +++ b/src/libraries/System.Private.CoreLib/src/System/DateTime.cs @@ -1806,7 +1806,8 @@ public string ToString([StringSyntax(StringSyntaxAttribute.DateTimeFormat)] stri public bool TryFormat(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) => DateTimeFormat.TryFormat(this, destination, out charsWritten, format, provider); - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] ReadOnlySpan format, IFormatProvider? provider) => + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) => DateTimeFormat.TryFormat(this, utf8Destination, out bytesWritten, format, provider); public DateTime ToUniversalTime() diff --git a/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs b/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs index 24b4275b3e958..77f1153181f67 100644 --- a/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs +++ b/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs @@ -862,7 +862,8 @@ public string ToString([StringSyntax(StringSyntaxAttribute.DateTimeFormat)] stri public bool TryFormat(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] ReadOnlySpan format = default, IFormatProvider? formatProvider = null) => DateTimeFormat.TryFormat(ClockDateTime, destination, out charsWritten, format, formatProvider, Offset); - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] ReadOnlySpan format, IFormatProvider? formatProvider) => + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] ReadOnlySpan format = default, IFormatProvider? formatProvider = null) => DateTimeFormat.TryFormat(ClockDateTime, utf8Destination, out bytesWritten, format, formatProvider, Offset); public DateTimeOffset ToUniversalTime() => diff --git a/src/libraries/System.Private.CoreLib/src/System/Decimal.cs b/src/libraries/System.Private.CoreLib/src/System/Decimal.cs index a0d257376ca6a..33b7acca438a2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Decimal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Decimal.cs @@ -504,8 +504,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatDecimal(this, format, NumberFormatInfo.GetInstance(provider), destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatDecimal(this, format, NumberFormatInfo.GetInstance(provider), utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Double.cs b/src/libraries/System.Private.CoreLib/src/System/Double.cs index 8af4921f6a7b2..523ad54c06047 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Double.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Double.cs @@ -366,8 +366,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatDouble(m_value, format, NumberFormatInfo.GetInstance(provider), destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatDouble(m_value, format, NumberFormatInfo.GetInstance(provider), utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs index b38edce0cf21a..a521731c65471 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs @@ -770,7 +770,7 @@ internal static void FormatFraction(ref ValueListBuilder result, i int charCount; bool formatted = typeof(TChar) == typeof(char) ? fraction.TryFormat(MemoryMarshal.Cast(chars), out charCount, fractionFormat, CultureInfo.InvariantCulture) : - ((IUtf8SpanFormattable)fraction).TryFormat(MemoryMarshal.Cast(chars), out charCount, fractionFormat, CultureInfo.InvariantCulture); + fraction.TryFormat(MemoryMarshal.Cast(chars), out charCount, fractionFormat, CultureInfo.InvariantCulture); Debug.Assert(charCount != 0); result.Append(chars.Slice(0, charCount)); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Half.cs b/src/libraries/System.Private.CoreLib/src/System/Half.cs index 3a7a2048e45a2..b462c88b6e390 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Half.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Half.cs @@ -540,8 +540,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatHalf(this, format, NumberFormatInfo.GetInstance(provider), destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatHalf(this, format, NumberFormatInfo.GetInstance(provider), utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Int128.cs b/src/libraries/System.Private.CoreLib/src/System/Int128.cs index 8247f5a600eac..d4f7c6a2c1928 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int128.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int128.cs @@ -119,8 +119,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatInt128(this, format, provider, destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatInt128(this, format, provider, utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Int16.cs b/src/libraries/System.Private.CoreLib/src/System/Int16.cs index 7286d104def07..2b3d0bf60d324 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int16.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int16.cs @@ -119,8 +119,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatInt32(m_value, 0x0000FFFF, format, provider, destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatInt32(m_value, 0x0000FFFF, format, provider, utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Int32.cs b/src/libraries/System.Private.CoreLib/src/System/Int32.cs index cff29460616af..dc1986c0098fa 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int32.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int32.cs @@ -129,8 +129,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatInt32(m_value, ~0, format, provider, destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatInt32(m_value, ~0, format, provider, utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Int64.cs b/src/libraries/System.Private.CoreLib/src/System/Int64.cs index 4d7143d4a8ebd..d8a3787917e16 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int64.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int64.cs @@ -126,8 +126,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatInt64(m_value, format, provider, destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatInt64(m_value, format, provider, utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs b/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs index f44bca5e46955..0457b6917bba9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs @@ -211,9 +211,9 @@ public int CompareTo(nint value) public bool TryFormat(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) => ((nint_t)_value).TryFormat(destination, out charsWritten, format, provider); - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) => - ((IUtf8SpanFormattable)(nint_t)_value).TryFormat(utf8Destination, out bytesWritten, format, provider); + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) => + ((nint_t)_value).TryFormat(utf8Destination, out bytesWritten, format, provider); public static nint Parse(string s) => (nint)nint_t.Parse(s); public static nint Parse(string s, NumberStyles style) => (nint)nint_t.Parse(s, style); diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs index 76d9473d7a490..5b1486858680e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs @@ -861,8 +861,8 @@ public int CompareTo(object? obj) /// true if the formatting was successful; otherwise, false. public bool TryFormat(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) => _value.TryFormat(destination, out charsWritten, format, provider); - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) => ((IUtf8SpanFormattable)_value).TryFormat(utf8Destination, out bytesWritten, format, provider); + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) => _value.TryFormat(utf8Destination, out bytesWritten, format, provider); // // IAdditiveIdentity diff --git a/src/libraries/System.Private.CoreLib/src/System/SByte.cs b/src/libraries/System.Private.CoreLib/src/System/SByte.cs index 9a95eecef3de4..610c5f5c6dd4e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SByte.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SByte.cs @@ -122,8 +122,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatInt32(m_value, 0x000000FF, format, provider, destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatInt32(m_value, 0x000000FF, format, provider, utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Single.cs b/src/libraries/System.Private.CoreLib/src/System/Single.cs index 7ca8590a3a36a..188534808e3a7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Single.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Single.cs @@ -358,8 +358,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatSingle(m_value, format, NumberFormatInfo.GetInstance(provider), destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatSingle(m_value, format, NumberFormatInfo.GetInstance(provider), utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs b/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs index a004175374dc5..7c402472df58f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs @@ -958,10 +958,11 @@ public string ToString([StringSyntax(StringSyntaxAttribute.TimeOnlyFormat)] stri /// An optional object that supplies culture-specific formatting information for destination. /// true if the formatting was successful; otherwise, false. /// The accepted standard formats are 'r', 'R', 'o', 'O', 't' and 'T'. - public bool TryFormat(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.TimeOnlyFormat)] ReadOnlySpan format = default(ReadOnlySpan), IFormatProvider? provider = null) => + public bool TryFormat(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.TimeOnlyFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) => TryFormatCore(destination, out charsWritten, format, provider); - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.TimeOnlyFormat)] ReadOnlySpan format, IFormatProvider? provider) => + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.TimeOnlyFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) => TryFormatCore(utf8Destination, out bytesWritten, format, provider); private bool TryFormatCore(Span destination, out int written, [StringSyntax(StringSyntaxAttribute.TimeOnlyFormat)] ReadOnlySpan format, IFormatProvider? provider) where TChar : unmanaged, IUtfChar diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeSpan.cs b/src/libraries/System.Private.CoreLib/src/System/TimeSpan.cs index 0a13fe4c42f4b..acaf1fc2661cd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeSpan.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeSpan.cs @@ -564,7 +564,8 @@ public string ToString([StringSyntax(StringSyntaxAttribute.TimeSpanFormat)] stri public bool TryFormat(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.TimeSpanFormat)] ReadOnlySpan format = default, IFormatProvider? formatProvider = null) => TimeSpanFormat.TryFormat(this, destination, out charsWritten, format, formatProvider); - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.TimeSpanFormat)] ReadOnlySpan format, IFormatProvider? formatProvider) => + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.TimeSpanFormat)] ReadOnlySpan format = default, IFormatProvider? formatProvider = null) => TimeSpanFormat.TryFormat(this, utf8Destination, out bytesWritten, format, formatProvider); #endregion diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt128.cs b/src/libraries/System.Private.CoreLib/src/System/UInt128.cs index 5a6d33150c3a3..c420c268fe018 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt128.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt128.cs @@ -120,8 +120,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatUInt128(this, format, provider, destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatUInt128(this, format, provider, utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt16.cs b/src/libraries/System.Private.CoreLib/src/System/UInt16.cs index 17a211c51b5ea..d43bd48fe68b0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt16.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt16.cs @@ -114,8 +114,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatUInt32(m_value, format, provider, destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatUInt32(m_value, format, provider, utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt32.cs b/src/libraries/System.Private.CoreLib/src/System/UInt32.cs index 9813330a72499..0a9f9c0aea125 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt32.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt32.cs @@ -124,8 +124,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatUInt32(m_value, format, provider, destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatUInt32(m_value, format, provider, utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt64.cs b/src/libraries/System.Private.CoreLib/src/System/UInt64.cs index da40613f88f7b..962064b83c310 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt64.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt64.cs @@ -123,8 +123,8 @@ public bool TryFormat(Span destination, out int charsWritten, [StringSynta return Number.TryFormatUInt64(m_value, format, provider, destination, out charsWritten); } - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { return Number.TryFormatUInt64(m_value, format, provider, utf8Destination, out bytesWritten); } diff --git a/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs b/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs index c91992cba0805..6c2d77d29779a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs @@ -207,9 +207,9 @@ public int CompareTo(nuint value) public bool TryFormat(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) => ((nuint_t)_value).TryFormat(destination, out charsWritten, format, provider); - /// - bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) => - ((IUtf8SpanFormattable)(nuint_t)_value).TryFormat(utf8Destination, out bytesWritten, format, provider); + /// + public bool TryFormat(Span utf8Destination, out int bytesWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) => + ((nuint_t)_value).TryFormat(utf8Destination, out bytesWritten, format, provider); public static nuint Parse(string s) => (nuint)nuint_t.Parse(s); public static nuint Parse(string s, NumberStyles style) => (nuint)nuint_t.Parse(s, style); diff --git a/src/libraries/System.Private.CoreLib/src/System/Version.cs b/src/libraries/System.Private.CoreLib/src/System/Version.cs index 611b209b1eaf9..2b13e362ee3a5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Version.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Version.cs @@ -185,6 +185,21 @@ public bool TryFormat(Span destination, out int charsWritten) => public bool TryFormat(Span destination, int fieldCount, out int charsWritten) => TryFormatCore(destination, fieldCount, out charsWritten); + /// Tries to format this version instance into a span of bytes. + /// The span in which to write this instance's value formatted as a span of UTF8 bytes. + /// When this method returns, contains the number of bytes that were written in . + /// if the formatting was successful; otherwise, . + public bool TryFormat(Span utf8Destination, out int bytesWritten) => + TryFormatCore(utf8Destination, DefaultFormatFieldCount, out bytesWritten); + + /// Tries to format this version instance into a span of bytes. + /// The span in which to write this instance's value formatted as a span of UTF8 bytes. + /// The number of components to return. This value ranges from 0 to 4. + /// When this method returns, contains the number of bytes that were written in . + /// if the formatting was successful; otherwise, . + public bool TryFormat(Span utf8Destination, int fieldCount, out int bytesWritten) => + TryFormatCore(utf8Destination, fieldCount, out bytesWritten); + private bool TryFormatCore(Span destination, int fieldCount, out int charsWritten) where TChar : unmanaged, IUtfChar { Debug.Assert(typeof(TChar) == typeof(char) || typeof(TChar) == typeof(byte)); @@ -235,7 +250,7 @@ static void ThrowArgumentException(string failureUpperBound) => int valueCharsWritten; bool formatted = typeof(TChar) == typeof(char) ? ((uint)value).TryFormat(MemoryMarshal.Cast(destination), out valueCharsWritten) : - ((IUtf8SpanFormattable)(uint)value).TryFormat(MemoryMarshal.Cast(destination), out valueCharsWritten, default, CultureInfo.InvariantCulture); + ((uint)value).TryFormat(MemoryMarshal.Cast(destination), out valueCharsWritten, default, CultureInfo.InvariantCulture); if (!formatted) { @@ -255,6 +270,7 @@ bool ISpanFormattable.TryFormat(Span destination, out int charsWritten, Re // format and provider are ignored. TryFormatCore(destination, DefaultFormatFieldCount, out charsWritten); + /// bool IUtf8SpanFormattable.TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider) => // format and provider are ignored. TryFormatCore(utf8Destination, DefaultFormatFieldCount, out bytesWritten); diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index a5699330cad7b..374d5ed8b0709 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -1479,7 +1479,7 @@ public static void Free(void* ptr) { } public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static System.Runtime.InteropServices.NFloat Truncate(System.Runtime.InteropServices.NFloat x) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Runtime.InteropServices.NFloat result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.Runtime.InteropServices.NFloat result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out System.Runtime.InteropServices.NFloat result) { throw null; } diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index c2ce193ceaf4f..a9fd59e5af115 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -879,7 +879,7 @@ public static void SetByte(System.Array array, int index, byte value) { } public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static byte TrailingZeroCount(byte value) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out byte result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out byte result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out byte result) { throw null; } @@ -1610,7 +1610,7 @@ public static partial class Convert public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("DateOnlyFormat")] string? format) { throw null; } public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("DateOnlyFormat")] string? format, System.IFormatProvider? provider) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("DateOnlyFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("TimeOnlyFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("DateOnlyFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out System.DateOnly result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.DateOnly result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, System.Globalization.DateTimeStyles style, out System.DateOnly result) { throw null; } @@ -1753,7 +1753,7 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("DateTimeFormat")] string? format, System.IFormatProvider? provider) { throw null; } public System.DateTime ToUniversalTime() { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("DateTimeFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("TimeOnlyFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("DateTimeFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out System.DateTime result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.DateTime result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, System.Globalization.DateTimeStyles styles, out System.DateTime result) { throw null; } @@ -1866,7 +1866,7 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public long ToUnixTimeMilliseconds() { throw null; } public long ToUnixTimeSeconds() { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("DateTimeFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? formatProvider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("TimeOnlyFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("DateTimeFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? formatProvider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan input, out System.DateTimeOffset result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.DateTimeOffset result) { throw null; } public static bool TryParse(System.ReadOnlySpan input, System.IFormatProvider? formatProvider, System.Globalization.DateTimeStyles styles, out System.DateTimeOffset result) { throw null; } @@ -2120,7 +2120,7 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public static ulong ToUInt64(decimal d) { throw null; } public static decimal Truncate(decimal d) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryGetBits(decimal d, System.Span destination, out int valuesWritten) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out decimal result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out decimal result) { throw null; } @@ -2363,7 +2363,7 @@ public DivideByZeroException(string? message, System.Exception? innerException) public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static double Truncate(double x) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out double result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out double result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out double result) { throw null; } @@ -3019,7 +3019,7 @@ public enum GCNotificationStatus public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static System.Half Truncate(System.Half x) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Half result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out System.Half result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.Half result) { throw null; } @@ -3320,7 +3320,7 @@ public InsufficientMemoryException(string? message, System.Exception? innerExcep public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static System.Int128 TrailingZeroCount(System.Int128 value) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Int128 result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.Int128 result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out System.Int128 result) { throw null; } @@ -3454,7 +3454,7 @@ public InsufficientMemoryException(string? message, System.Exception? innerExcep public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static short TrailingZeroCount(short value) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out short result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out short result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out short result) { throw null; } @@ -3588,7 +3588,7 @@ public InsufficientMemoryException(string? message, System.Exception? innerExcep public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static int TrailingZeroCount(int value) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out int result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out int result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out int result) { throw null; } @@ -3722,7 +3722,7 @@ public InsufficientMemoryException(string? message, System.Exception? innerExcep public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static long TrailingZeroCount(long value) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out long result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out long result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out long result) { throw null; } @@ -3863,7 +3863,7 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static nint TrailingZeroCount(nint value) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out nint result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out nint result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out nint result) { throw null; } @@ -4851,7 +4851,7 @@ public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, S public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static sbyte TrailingZeroCount(sbyte value) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out sbyte result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out sbyte result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out sbyte result) { throw null; } @@ -5049,7 +5049,7 @@ public SerializableAttribute() { } public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static float Truncate(float x) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out float result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out float result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out float result) { throw null; } @@ -5443,7 +5443,7 @@ public ThreadStaticAttribute() { } public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("TimeOnlyFormat")] string? format, System.IFormatProvider? provider) { throw null; } public System.TimeSpan ToTimeSpan() { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("TimeOnlyFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("TimeOnlyFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("TimeOnlyFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, System.Globalization.DateTimeStyles style, out System.TimeOnly result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.TimeOnly result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out System.TimeOnly result) { throw null; } @@ -5549,7 +5549,7 @@ public TimeoutException(string? message, System.Exception? innerException) { } public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("TimeSpanFormat")] string? format) { throw null; } public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("TimeSpanFormat")] string? format, System.IFormatProvider? formatProvider) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("TimeSpanFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? formatProvider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("TimeSpanFormat")] System.ReadOnlySpan format, System.IFormatProvider? formatProvider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("TimeSpanFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? formatProvider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan input, System.IFormatProvider? formatProvider, out System.TimeSpan result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out System.TimeSpan result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? input, System.IFormatProvider? formatProvider, out System.TimeSpan result) { throw null; } @@ -6448,7 +6448,7 @@ public TypeUnloadedException(string? message, System.Exception? innerException) public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static System.UInt128 TrailingZeroCount(System.UInt128 value) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.UInt128 result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out System.UInt128 result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out System.UInt128 result) { throw null; } @@ -6582,7 +6582,7 @@ public TypeUnloadedException(string? message, System.Exception? innerException) public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static ushort TrailingZeroCount(ushort value) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out ushort result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out ushort result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out ushort result) { throw null; } @@ -6716,7 +6716,7 @@ public TypeUnloadedException(string? message, System.Exception? innerException) public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static uint TrailingZeroCount(uint value) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out uint result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out uint result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out uint result) { throw null; } @@ -6850,7 +6850,7 @@ public TypeUnloadedException(string? message, System.Exception? innerException) public string ToString([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] string? format, System.IFormatProvider? provider) { throw null; } public static ulong TrailingZeroCount(ulong value) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out ulong result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out ulong result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out ulong result) { throw null; } @@ -6987,7 +6987,7 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public ulong ToUInt64() { throw null; } public static nuint TrailingZeroCount(nuint value) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } - bool System.IUtf8SpanFormattable.TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format, System.IFormatProvider? provider) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("NumericFormat")] System.ReadOnlySpan format = default(System.ReadOnlySpan), System.IFormatProvider? provider = null) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out nuint result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.IFormatProvider? provider, out nuint result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out nuint result) { throw null; } @@ -7231,6 +7231,8 @@ public Version(string version) { } public string ToString(int fieldCount) { throw null; } public bool TryFormat(System.Span destination, int fieldCount, out int charsWritten) { throw null; } public bool TryFormat(System.Span destination, out int charsWritten) { throw null; } + public bool TryFormat(System.Span utf8Destination, int fieldCount, out int bytesWritten) { throw null; } + public bool TryFormat(System.Span utf8Destination, out int bytesWritten) { throw null; } public static bool TryParse(System.ReadOnlySpan input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Version? result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Version? result) { throw null; } } diff --git a/src/libraries/System.Runtime/tests/System/DateOnlyTests.cs b/src/libraries/System.Runtime/tests/System/DateOnlyTests.cs index 9a844baac2365..d32f4c391fc8e 100644 --- a/src/libraries/System.Runtime/tests/System/DateOnlyTests.cs +++ b/src/libraries/System.Runtime/tests/System/DateOnlyTests.cs @@ -540,16 +540,16 @@ public static void TryFormatTest() Span buffer = stackalloc byte[100]; DateOnly dateOnly = DateOnly.FromDateTime(DateTime.Today); - Assert.True(((IUtf8SpanFormattable)dateOnly).TryFormat(buffer, out int charsWritten, default, null)); - Assert.True(((IUtf8SpanFormattable)dateOnly).TryFormat(buffer, out charsWritten, "o", null)); + Assert.True(dateOnly.TryFormat(buffer, out int charsWritten, default, null)); + Assert.True(dateOnly.TryFormat(buffer, out charsWritten, "o", null)); Assert.Equal(10, charsWritten); - Assert.True(((IUtf8SpanFormattable)dateOnly).TryFormat(buffer, out charsWritten, "R", null)); + Assert.True(dateOnly.TryFormat(buffer, out charsWritten, "R", null)); Assert.Equal(16, charsWritten); - Assert.False(((IUtf8SpanFormattable)dateOnly).TryFormat(buffer.Slice(0, 3), out charsWritten, default, null)); - Assert.False(((IUtf8SpanFormattable)dateOnly).TryFormat(buffer.Slice(0, 3), out charsWritten, "r", null)); - Assert.False(((IUtf8SpanFormattable)dateOnly).TryFormat(buffer.Slice(0, 3), out charsWritten, "O", null)); - Assert.Throws(() => ((IUtf8SpanFormattable)dateOnly).TryFormat(stackalloc byte[100], out charsWritten, "u", null)); - Assert.Throws(() => ((IUtf8SpanFormattable)dateOnly).TryFormat(stackalloc byte[100], out charsWritten, "hh-ss", null)); + Assert.False(dateOnly.TryFormat(buffer.Slice(0, 3), out charsWritten, default, null)); + Assert.False(dateOnly.TryFormat(buffer.Slice(0, 3), out charsWritten, "r", null)); + Assert.False(dateOnly.TryFormat(buffer.Slice(0, 3), out charsWritten, "O", null)); + Assert.Throws(() => dateOnly.TryFormat(stackalloc byte[100], out charsWritten, "u", null)); + Assert.Throws(() => dateOnly.TryFormat(stackalloc byte[100], out charsWritten, "hh-ss", null)); Assert.Throws(() => $"{dateOnly:u}"); Assert.Throws(() => $"{dateOnly:hh-ss}"); } diff --git a/src/libraries/System.Runtime/tests/System/DateTimeOffsetTests.cs b/src/libraries/System.Runtime/tests/System/DateTimeOffsetTests.cs index aff32a78d2aae..6fe8e0e1b38ba 100644 --- a/src/libraries/System.Runtime/tests/System/DateTimeOffsetTests.cs +++ b/src/libraries/System.Runtime/tests/System/DateTimeOffsetTests.cs @@ -1474,19 +1474,19 @@ public static void TryFormat_ToString_EqualResults() // Just the right amount of space, succeeds Span actual = new byte[expectedString.Length]; - Assert.True(((IUtf8SpanFormattable)expected).TryFormat(actual, out int charsWritten, default, null)); - Assert.Equal(expectedString.Length, charsWritten); + Assert.True(expected.TryFormat(actual, out int bytesWritten, default, null)); + Assert.Equal(expectedString.Length, bytesWritten); Assert.Equal(expectedString, Encoding.UTF8.GetString(actual)); // Too little space, fails actual = new byte[expectedString.Length - 1]; - Assert.False(((IUtf8SpanFormattable)expected).TryFormat(actual, out charsWritten, default, null)); - Assert.Equal(0, charsWritten); + Assert.False(expected.TryFormat(actual, out bytesWritten, default, null)); + Assert.Equal(0, bytesWritten); // More than enough space, succeeds actual = new byte[expectedString.Length + 1]; - Assert.True(((IUtf8SpanFormattable)expected).TryFormat(actual, out charsWritten, default, null)); - Assert.Equal(expectedString.Length, charsWritten); + Assert.True(expected.TryFormat(actual, out bytesWritten, default, null)); + Assert.Equal(expectedString.Length, bytesWritten); Assert.Equal(expectedString, Encoding.UTF8.GetString(actual.Slice(0, expectedString.Length))); Assert.Equal(0, actual[actual.Length - 1]); } @@ -1512,10 +1512,10 @@ public static void TryFormat_MatchesExpected(DateTimeOffset dateTimeOffset, stri { var destination = new byte[expected.Length]; - Assert.False(((IUtf8SpanFormattable)dateTimeOffset).TryFormat(destination.AsSpan(0, destination.Length - 1), out _, format, provider)); + Assert.False(dateTimeOffset.TryFormat(destination.AsSpan(0, destination.Length - 1), out _, format, provider)); - Assert.True(((IUtf8SpanFormattable)dateTimeOffset).TryFormat(destination, out int charsWritten, format, provider)); - Assert.Equal(destination.Length, charsWritten); + Assert.True(dateTimeOffset.TryFormat(destination, out int bytesWritten, format, provider)); + Assert.Equal(destination.Length, bytesWritten); Assert.Equal(expected, Encoding.UTF8.GetString(destination)); } } diff --git a/src/libraries/System.Runtime/tests/System/DateTimeTests.cs b/src/libraries/System.Runtime/tests/System/DateTimeTests.cs index 469c10a8cb436..716f4139a3c43 100644 --- a/src/libraries/System.Runtime/tests/System/DateTimeTests.cs +++ b/src/libraries/System.Runtime/tests/System/DateTimeTests.cs @@ -2664,18 +2664,18 @@ public static void TryFormat_MatchesToString(string format) { // Just the right length, succeeds Span dest = new byte[expected.Length]; - Assert.True(((IUtf8SpanFormattable)dt).TryFormat(dest, out int bytesWritten, format, null)); + Assert.True(dt.TryFormat(dest, out int bytesWritten, format)); Assert.Equal(expected.Length, bytesWritten); Assert.Equal(expected, Encoding.UTF8.GetString(dest)); // Too short, fails dest = new byte[expected.Length - 1]; - Assert.False(((IUtf8SpanFormattable)dt).TryFormat(dest, out bytesWritten, format, null)); + Assert.False(dt.TryFormat(dest, out bytesWritten, format)); Assert.Equal(0, bytesWritten); // Longer than needed, succeeds dest = new byte[expected.Length + 1]; - Assert.True(((IUtf8SpanFormattable)dt).TryFormat(dest, out bytesWritten, format, null)); + Assert.True(dt.TryFormat(dest, out bytesWritten, format)); Assert.Equal(expected.Length, bytesWritten); Assert.Equal(expected, Encoding.UTF8.GetString(dest.Slice(0, expected.Length))); Assert.Equal(0, dest[dest.Length - 1]); @@ -2702,9 +2702,9 @@ public static void TryFormat_MatchesExpected(DateTime dateTime, string format, I { var destination = new byte[expected.Length]; - Assert.False(((IUtf8SpanFormattable)dateTime).TryFormat(destination.AsSpan(0, destination.Length - 1), out _, format, provider)); + Assert.False(dateTime.TryFormat(destination.AsSpan(0, destination.Length - 1), out _, format, provider)); - Assert.True(((IUtf8SpanFormattable)dateTime).TryFormat(destination, out int byteWritten, format, provider)); + Assert.True(dateTime.TryFormat(destination, out int byteWritten, format, provider)); Assert.Equal(destination.Length, byteWritten); Assert.Equal(expected, Encoding.UTF8.GetString(destination)); } diff --git a/src/libraries/System.Runtime/tests/System/TimeOnlyTests.cs b/src/libraries/System.Runtime/tests/System/TimeOnlyTests.cs index cc833cfe5c27d..75f14b5ab4f6b 100644 --- a/src/libraries/System.Runtime/tests/System/TimeOnlyTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeOnlyTests.cs @@ -597,27 +597,27 @@ public static void TryFormatTest() TimeOnly timeOnly = TimeOnly.FromDateTime(DateTime.Now); buffer.Fill((byte)' '); - Assert.True(((IUtf8SpanFormattable)timeOnly).TryFormat(buffer, out int charsWritten, default, null)); - Assert.Equal(charsWritten, buffer.TrimEnd(" "u8).Length); + Assert.True(timeOnly.TryFormat(buffer, out int bytesWritten)); + Assert.Equal(bytesWritten, buffer.TrimEnd(" "u8).Length); buffer.Fill((byte)' '); - Assert.True(((IUtf8SpanFormattable)timeOnly).TryFormat(buffer, out charsWritten, "o", null)); - Assert.Equal(16, charsWritten); + Assert.True(timeOnly.TryFormat(buffer, out bytesWritten, "o")); + Assert.Equal(16, bytesWritten); Assert.Equal(16, buffer.TrimEnd(" "u8).Length); buffer.Fill((byte)' '); - Assert.True(((IUtf8SpanFormattable)timeOnly).TryFormat(buffer, out charsWritten, "R", null)); - Assert.Equal(8, charsWritten); + Assert.True(timeOnly.TryFormat(buffer, out bytesWritten, "R")); + Assert.Equal(8, bytesWritten); Assert.Equal(8, buffer.TrimEnd(" "u8).Length); - Assert.False(((IUtf8SpanFormattable)timeOnly).TryFormat(buffer.Slice(0, 3), out charsWritten, default, null)); - Assert.False(((IUtf8SpanFormattable)timeOnly).TryFormat(buffer.Slice(0, 3), out charsWritten, "r", null)); - Assert.False(((IUtf8SpanFormattable)timeOnly).TryFormat(buffer.Slice(0, 3), out charsWritten, "O", null)); + Assert.False(timeOnly.TryFormat(buffer.Slice(0, 3), out bytesWritten)); + Assert.False(timeOnly.TryFormat(buffer.Slice(0, 3), out bytesWritten, "r")); + Assert.False(timeOnly.TryFormat(buffer.Slice(0, 3), out bytesWritten, "O")); - Assert.Throws(() => ((IUtf8SpanFormattable)timeOnly).TryFormat(new byte[100], out charsWritten, "u", null)); - Assert.Throws(() => ((IUtf8SpanFormattable)timeOnly).TryFormat(new byte[100], out charsWritten, "dd-yyyy", null)); - Assert.Throws(() => $"{((IUtf8SpanFormattable)timeOnly):u}"); - Assert.Throws(() => $"{((IUtf8SpanFormattable)timeOnly):dd-yyyy}"); + Assert.Throws(() => timeOnly.TryFormat(new byte[100], out bytesWritten, "u")); + Assert.Throws(() => timeOnly.TryFormat(new byte[100], out bytesWritten, "dd-yyyy")); + Assert.Throws(() => $"{timeOnly:u}"); + Assert.Throws(() => $"{timeOnly:dd-yyyy}"); } } } diff --git a/src/libraries/System.Runtime/tests/System/TimeSpanTests.cs b/src/libraries/System.Runtime/tests/System/TimeSpanTests.cs index 6bcd82c3e3128..de434b059fad9 100644 --- a/src/libraries/System.Runtime/tests/System/TimeSpanTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeSpanTests.cs @@ -1450,16 +1450,16 @@ public static void TryFormat_Valid(TimeSpan input, string format, CultureInfo in Span dst; dst = new byte[expected.Length - 1]; - Assert.False(((IUtf8SpanFormattable)input).TryFormat(dst, out bytesWritten, format, info)); + Assert.False(input.TryFormat(dst, out bytesWritten, format, info)); Assert.Equal(0, bytesWritten); dst = new byte[expected.Length]; - Assert.True(((IUtf8SpanFormattable)input).TryFormat(dst, out bytesWritten, format, info)); + Assert.True(input.TryFormat(dst, out bytesWritten, format, info)); Assert.Equal(expected.Length, bytesWritten); Assert.Equal(expected, Encoding.UTF8.GetString(dst)); dst = new byte[expected.Length + 1]; - Assert.True(((IUtf8SpanFormattable)input).TryFormat(dst, out bytesWritten, format, info)); + Assert.True(input.TryFormat(dst, out bytesWritten, format, info)); Assert.Equal(expected.Length, bytesWritten); Assert.Equal(expected, Encoding.UTF8.GetString(dst.Slice(0, dst.Length - 1))); Assert.Equal(0, dst[dst.Length - 1]); diff --git a/src/libraries/System.Runtime/tests/System/VersionTests.cs b/src/libraries/System.Runtime/tests/System/VersionTests.cs index 06ee0e0e13cbc..bd03365d7007a 100644 --- a/src/libraries/System.Runtime/tests/System/VersionTests.cs +++ b/src/libraries/System.Runtime/tests/System/VersionTests.cs @@ -370,65 +370,46 @@ private static void VerifyVersion(Version version, int major, int minor, int bui [MemberData(nameof(ToString_TestData))] public static void TryFormat_Invoke_WritesExpected(Version version, string[] expected) { - char[] dest; - int charsWritten; - - for (int i = 0; i < expected.Length; i++) + // UTF16 { - if (i > 0) + byte[] dest; + int bytesWritten; + + for (int i = 0; i < expected.Length; i++) { - // Too small - dest = new char[expected[i].Length - 1]; - Assert.False(version.TryFormat(dest, i, out charsWritten)); - Assert.Equal(0, charsWritten); + byte[] expectedBytes = Encoding.UTF8.GetBytes(expected[i]); + + if (i > 0) + { + // Too small + dest = new byte[expectedBytes.Length - 1]; + Assert.False(version.TryFormat(dest, i, out bytesWritten)); + Assert.Equal(0, bytesWritten); + } + + // Just right + dest = new byte[expectedBytes.Length]; + Assert.True(version.TryFormat(dest, i, out bytesWritten)); + Assert.Equal(expectedBytes.Length, bytesWritten); + Assert.Equal(expectedBytes, dest.AsSpan(0, bytesWritten).ToArray()); + + // More than needed + dest = new byte[expectedBytes.Length + 10]; + Assert.True(version.TryFormat(dest, i, out bytesWritten)); + Assert.Equal(expectedBytes.Length, bytesWritten); + Assert.Equal(expectedBytes, dest.AsSpan(0, bytesWritten).ToArray()); } - // Just right - dest = new char[expected[i].Length]; - Assert.True(version.TryFormat(dest, i, out charsWritten)); - Assert.Equal(expected[i].Length, charsWritten); - Assert.Equal(expected[i], new string(dest, 0, charsWritten)); - - // More than needed - dest = new char[expected[i].Length + 10]; - Assert.True(version.TryFormat(dest, i, out charsWritten)); - Assert.Equal(expected[i].Length, charsWritten); - Assert.Equal(expected[i], new string(dest, 0, charsWritten)); - } + int maxFieldCount = expected.Length - 1; + dest = new byte[Encoding.UTF8.GetByteCount(expected[maxFieldCount])]; + Assert.True(version.TryFormat(dest, out bytesWritten)); + Assert.Equal(dest.Length, bytesWritten); + Assert.Equal(Encoding.UTF8.GetBytes(expected[maxFieldCount]), dest.AsSpan(0, bytesWritten).ToArray()); - int maxFieldCount = expected.Length - 1; - dest = new char[expected[maxFieldCount].Length]; - Assert.True(version.TryFormat(dest, out charsWritten)); - Assert.Equal(expected[maxFieldCount].Length, charsWritten); - Assert.Equal(expected[maxFieldCount], new string(dest, 0, charsWritten)); - - dest = new char[0]; - AssertExtensions.Throws("fieldCount", () => version.TryFormat(dest, -1, out charsWritten)); // Index < 0 - AssertExtensions.Throws("fieldCount", () => version.TryFormat(dest, maxFieldCount + 1, out charsWritten)); // Index > version.fieldCount - } - - [Theory] - [MemberData(nameof(ToString_TestData))] - public static void IUtf8SpanFormattableTryFormat_Invoke_WritesExpected(Version version, string[] expectedFieldCounts) - { - string expected = expectedFieldCounts[^1]; - - // Too small - byte[] dest = new byte[expected.Length - 1]; - Assert.False(((IUtf8SpanFormattable)version).TryFormat(dest, out int charsWritten, default, null)); - Assert.Equal(0, charsWritten); - - // Just right - dest = new byte[expected.Length]; - Assert.True(((IUtf8SpanFormattable)version).TryFormat(dest, out charsWritten, default, null)); - Assert.Equal(expected.Length, charsWritten); - Assert.Equal(expected, Encoding.UTF8.GetString(dest.AsSpan(0, charsWritten))); - - // More than needed - dest = new byte[expected.Length + 10]; - Assert.True(((IUtf8SpanFormattable)version).TryFormat(dest, out charsWritten, default, null)); - Assert.Equal(expected.Length, charsWritten); - Assert.Equal(expected, Encoding.UTF8.GetString(dest.AsSpan(0, charsWritten))); + dest = new byte[0]; + AssertExtensions.Throws("fieldCount", () => version.TryFormat(dest, -1, out bytesWritten)); // Index < 0 + AssertExtensions.Throws("fieldCount", () => version.TryFormat(dest, maxFieldCount + 1, out bytesWritten)); // Index > version.fieldCount + } } } }