Example #1
0
        public static unsafe object RhBox(EETypePtr pEEType, ref byte data)
        {
            EEType *ptrEEType  = (EEType *)pEEType.ToPointer();
            int     dataOffset = 0;
            object  result;

            // If we're boxing a Nullable<T> then either box the underlying T or return null (if the
            // nullable's value is empty).
            if (ptrEEType->IsNullable)
            {
                // The boolean which indicates whether the value is null comes first in the Nullable struct.
                if (data == 0)
                {
                    return(null);
                }

                // Switch type we're going to box to the Nullable<T> target type and advance the data pointer
                // to the value embedded within the nullable.
                dataOffset = ptrEEType->NullableValueOffset;
                ptrEEType  = ptrEEType->NullableType;
            }

#if FEATURE_64BIT_ALIGNMENT
            if (ptrEEType->RequiresAlign8)
            {
                result = InternalCalls.RhpNewFastMisalign(ptrEEType);
            }
            else
#endif // FEATURE_64BIT_ALIGNMENT
            {
                result = InternalCalls.RhpNewFast(ptrEEType);
            }
            InternalCalls.RhpBox(result, ref Unsafe.Add(ref data, dataOffset));
            return(result);
        }
Example #2
0
        public unsafe static object RhBox(EETypePtr pEEType, void *pData)
        {
            EEType *ptrEEType = (EEType *)pEEType.ToPointer();
            object  result;

            // If we're boxing a Nullable<T> then either box the underlying T or return null (if the
            // nullable's value is empty).
            if (ptrEEType->IsNullable)
            {
                // The boolean which indicates whether the value is null comes first in the Nullable struct.
                if (!*(bool *)pData)
                {
                    return(null);
                }

                // Switch type we're going to box to the Nullable<T> target type and advance the data pointer
                // to the value embedded within the nullable.
                pData     = (byte *)pData + ptrEEType->GetNullableValueOffset();
                ptrEEType = ptrEEType->GetNullableType();
            }

#if FEATURE_64BIT_ALIGNMENT
            if (ptrEEType->RequiresAlign8)
            {
                result = InternalCalls.RhpNewFastMisalign(ptrEEType);
            }
            else
#endif // FEATURE_64BIT_ALIGNMENT
            {
                result = InternalCalls.RhpNewFast(ptrEEType);
            }
            if (result == null)
            {
                // Throw the out of memory exception defined by the classlib, using the input EEType*
                // to find the correct classlib.

                ExceptionIDs exID = ExceptionIDs.OutOfMemory;

                IntPtr    addr = pEEType.ToPointer()->GetAssociatedModuleAddress();
                Exception e    = EH.GetClasslibException(exID, addr);
                throw e;
            }
            InternalCalls.RhpBox(result, pData);
            return(result);
        }