using System; using System.Buffers; using System.Buffers.Text; namespace Cysharp.Text { public partial struct Utf8ValueStringBuilder { static object? CreateFormatter(Type type) { if (type == typeof(System.Byte)) { return new TryFormat((System.Byte x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.DateTime)) { return new TryFormat((System.DateTime x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.DateTimeOffset)) { return new TryFormat((System.DateTimeOffset x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.Decimal)) { return new TryFormat((System.Decimal x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.Double)) { return new TryFormat((System.Double x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.Int16)) { return new TryFormat((System.Int16 x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.Int32)) { return new TryFormat((System.Int32 x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.Int64)) { return new TryFormat((System.Int64 x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.SByte)) { return new TryFormat((System.SByte x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.Single)) { return new TryFormat((System.Single x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.TimeSpan)) { return new TryFormat((System.TimeSpan x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.UInt16)) { return new TryFormat((System.UInt16 x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.UInt32)) { return new TryFormat((System.UInt32 x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.UInt64)) { return new TryFormat((System.UInt64 x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.Guid)) { return new TryFormat((System.Guid x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.Boolean)) { return new TryFormat((System.Boolean x, Span dest, out int written, StandardFormat format) => Utf8Formatter.TryFormat(x, dest, out written, format)); } if (type == typeof(System.Byte?)) { return CreateNullableFormatter(); } if (type == typeof(System.DateTime?)) { return CreateNullableFormatter(); } if (type == typeof(System.DateTimeOffset?)) { return CreateNullableFormatter(); } if (type == typeof(System.Decimal?)) { return CreateNullableFormatter(); } if (type == typeof(System.Double?)) { return CreateNullableFormatter(); } if (type == typeof(System.Int16?)) { return CreateNullableFormatter(); } if (type == typeof(System.Int32?)) { return CreateNullableFormatter(); } if (type == typeof(System.Int64?)) { return CreateNullableFormatter(); } if (type == typeof(System.SByte?)) { return CreateNullableFormatter(); } if (type == typeof(System.Single?)) { return CreateNullableFormatter(); } if (type == typeof(System.TimeSpan?)) { return CreateNullableFormatter(); } if (type == typeof(System.UInt16?)) { return CreateNullableFormatter(); } if (type == typeof(System.UInt32?)) { return CreateNullableFormatter(); } if (type == typeof(System.UInt64?)) { return CreateNullableFormatter(); } if (type == typeof(System.Guid?)) { return CreateNullableFormatter(); } if (type == typeof(System.Boolean?)) { return CreateNullableFormatter(); } if (type == typeof(System.IntPtr)) { return new TryFormat((System.IntPtr x, Span dest, out int written, StandardFormat format) => System.IntPtr.Size == 4 ? Utf8Formatter.TryFormat(x.ToInt32(), dest, out written, format) : Utf8Formatter.TryFormat(x.ToInt64(), dest, out written, format)); } if (type == typeof(System.UIntPtr)) { return new TryFormat((System.UIntPtr x, Span dest, out int written, StandardFormat format) => System.UIntPtr.Size == 4 ? Utf8Formatter.TryFormat(x.ToUInt32(), dest, out written, format) : Utf8Formatter.TryFormat(x.ToUInt64(), dest, out written, format)); } return null; } } }