fix: Adds ISpanFormattable to Geometry structs (#1231)
* Adds ISpanFormattable to geometry structs and makes ToString() near-zero-allocation. * Adds IEquatable, and Parsable to Rectangle3D to get it in-line with the other structs. Closes #1067
This commit is contained in:
parent
c75bde55da
commit
d7d914df6c
12 changed files with 721 additions and 195 deletions
|
|
@ -118,9 +118,22 @@ public readonly struct Serial : IComparable<Serial>, IComparable<uint>, IEquatab
|
|||
public static Serial operator --(Serial l) => (Serial)(l.Value - 1);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override string ToString() => $"{this}";
|
||||
public override string ToString()
|
||||
{
|
||||
// Maximum number of characters that are needed to represent this:
|
||||
// 2 characters for 0x
|
||||
// Up to 8 characters to represent the value in hex
|
||||
Span<char> span = stackalloc char[10];
|
||||
TryFormat(span, out var charsWritten, null, null);
|
||||
return span[..charsWritten].ToString();
|
||||
}
|
||||
|
||||
public string ToString(string format, IFormatProvider formatProvider) => ToString();
|
||||
public string ToString(string format, IFormatProvider formatProvider)
|
||||
{
|
||||
// format and formatProvider are not doing anything right now, so use the
|
||||
// default ToString implementation.
|
||||
return ToString();
|
||||
}
|
||||
|
||||
public bool TryFormat(
|
||||
Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider provider
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue