예제 #1
0
 // IL code: sizeof
 public unsafe static int SizeOf <T>(RuntimeTypeHandle typeHandle)
 {
     if (RuntimeAugments.IsValueType(typeHandle))
     {
         return(typeHandle.GetValueTypeSize());
     }
     else
     {
         return(sizeof(IntPtr));
     }
 }
예제 #2
0
        public override int GetStructUnsafeStructSize(RuntimeTypeHandle structureTypeHandle)
        {
            if (TryGetStructUnsafeStructSize(structureTypeHandle, out int size))
            {
                return(size);
            }

            // IsBlittable() checks whether the type contains GC references. It is approximate check with false positives.
            // This fallback path will return incorrect answer for types that do not contain GC references, but that are
            // not actually blittable; e.g. for types with bool fields.
            if (structureTypeHandle.IsBlittable() && structureTypeHandle.IsValueType())
            {
                return(structureTypeHandle.GetValueTypeSize());
            }

            throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
        }
예제 #3
0
파일: SafeBuffer.cs 프로젝트: wffy/corert
        private static int SizeOf(Type t)
        {
            Debug.Assert(t != null, "t");

            if (t.TypeHandle.IsGenericType())
            {
                throw new ArgumentException(SR.Argument_NeedNonGenericType, "t");
            }

            RuntimeTypeHandle typeHandle = t.TypeHandle;

            if (!(typeHandle.IsBlittable() && typeHandle.IsValueType()))
            {
                throw new ArgumentException(SR.Argument_NeedStructWithNoRefs);
            }

            return(typeHandle.GetValueTypeSize());
        }