示例#1
0
 public static void AssertSize <T>(ElementSize elementSize)
 {
     if (TypeHelpers.ToElementSize <T>() != elementSize)
     {
         throw new InvalidOperationException($"Element size mismatch, T is {Unsafe.SizeOf<T>()}, pointer is {elementSize}");
     }
 }
示例#2
0
        private ElementSize GetElementSize()
        {
            if (ReflectionCache <T> .ImplementsIStruct)
            {
                return(ReflectionCache <T> .PreferredElementSize);
            }
            else if (ReflectionCache <T> .ImplementsIAbsPointer)
            {
                return(ElementSize.EightBytesPointer);
            }
            else if (typeof(T) == typeof(Void))
            {
                return(ElementSize.Zero);
            }

            return(TypeHelpers.ToElementSize <T>());
        }