public static void Register <T>(UnmanagedFormatterDelegate <T> formatter) where T : unmanaged { lock (_unmanagedStructs) { _unmanagedStructs[typeof(T).TypeHandle.Value] = (b, vp, view) => FormatterGeneric(b, vp, view, formatter); _unmanagedStructs[typeof(T?).TypeHandle.Value] = (b, vp, view) => FormatterGenericNullable(b, vp, view, formatter); } }
public static void Register <T>() where T : unmanaged, IStringFormattable { UnmanagedFormatterDelegate <T> formatter = (ref T input, StringBuffer buffer, StringView view) => input.Format(buffer, view); lock (_unmanagedStructs) { _unmanagedStructs[typeof(T).TypeHandle.Value] = (b, vp, view) => FormatterGeneric(b, vp, view, formatter); _unmanagedStructs[typeof(T?).TypeHandle.Value] = (b, vp, view) => FormatterGenericNullable(b, vp, view, formatter); } }
public static void RegisterUnmanaged <T>(UnmanagedFormatterDelegate <T> formatter) where T : unmanaged => UnmanagedCache.Register(formatter);
private static void FormatterGenericNullable <T>(StringBuffer stringBuffer, byte *valuePtr, StringView view, UnmanagedFormatterDelegate <T> typedFormatter) where T : unmanaged { ref var typedValueRef = ref UnsafeTools.AsRef <T?>(valuePtr);
private static void FormatterGeneric <T>(StringBuffer stringBuffer, byte *valuePtr, StringView view, UnmanagedFormatterDelegate <T> typedFormatter) where T : unmanaged { typedFormatter?.Invoke(ref UnsafeTools.AsRef <T>(valuePtr), stringBuffer, view); }