Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public T Read<T>()
- {
- if (TypeCache<T>.CanUsePadding16)
- return Unsafe.As<Padding16, T>(ref _valueStorage);
- return (T)_defaultStorage;
- }
- public static class TypeCache<T>
- {
- public static readonly bool CanUsePadding16;
- static TypeCache()
- {
- CanUsePadding16 =
- !IsReferenceOrContainsReferences(typeof(T)) && Unsafe.SizeOf<T>() <= 16;
- }
- private static bool IsReferenceOrContainsReferences(Type type)
- {
- // Custom implementation using reflection
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement