public unsafe static void RhUnboxAny(object o, ref Hack_o_p data, EETypePtr pUnboxToEEType) { EEType *ptrUnboxToEEType = (EEType *)pUnboxToEEType.ToPointer(); if (ptrUnboxToEEType->IsValueType) { // HACK: we would really want to take the address of o here, // but the rules of the C# language don't let us do that, // so we arrive at the same result by taking the address of p // and going back one pointer-sized unit fixed(IntPtr *pData = &data.p) { bool isValid = false; if (ptrUnboxToEEType->IsNullable) { isValid = (o == null) || TypeCast.AreTypesEquivalentInternal(o.EEType, ptrUnboxToEEType->GetNullableType()); } else if (o != null) { isValid = UnboxAnyTypeCompare(o.EEType, ptrUnboxToEEType); } if (!isValid) { // Throw the invalid cast exception defined by the classlib, using the input unbox EEType* // to find the correct classlib. ExceptionIDs exID = o == null ? ExceptionIDs.NullReference : ExceptionIDs.InvalidCast; IntPtr addr = ptrUnboxToEEType->GetAssociatedModuleAddress(); Exception e = EH.GetClasslibException(exID, addr); BinderIntrinsics.TailCall_RhpThrowEx(e); } InternalCalls.RhUnbox(o, pData - 1, ptrUnboxToEEType); } } else { if (o == null || (TypeCast.IsInstanceOf(o, ptrUnboxToEEType) != null)) { data.o = o; } else { IntPtr addr = ptrUnboxToEEType->GetAssociatedModuleAddress(); Exception e = EH.GetClasslibException(ExceptionIDs.InvalidCast, addr); BinderIntrinsics.TailCall_RhpThrowEx(e); } } }
static public unsafe bool RhBoxAndNullCheck(ref Hack_o_p data, EETypePtr pEEType) { EEType *ptrEEType = (EEType *)pEEType.ToPointer(); if (ptrEEType->IsValueType) { return(true); } else { return(data.o != null); } }
static public unsafe void RhUnboxNullable(ref Hack_o_p data, EETypePtr pUnboxToEEType, Object obj) { EEType *ptrUnboxToEEType = (EEType *)pUnboxToEEType.ToPointer(); // HACK: we would really want to take the address of o here, // but the rules of the C# language don't let us do that, // so we arrive at the same result by taking the address of p // and going back one pointer-sized unit fixed(IntPtr *pData = &data.p) { if ((obj != null) && (obj.EEType != ptrUnboxToEEType->NullableType)) { throw ptrUnboxToEEType->GetClasslibException(ExceptionIDs.InvalidCast); } InternalCalls.RhUnbox(obj, pData - 1, ptrUnboxToEEType); } }
static public unsafe void RhArrayStoreCheckAny(object array, ref Hack_o_p data) { if (array == null) { return; } Debug.Assert(array.EEType->IsArray, "first argument must be an array"); EEType *arrayElemType = array.EEType->RelatedParameterType; if (arrayElemType->IsValueType) { return; } TypeCast.CheckArrayStore(array, data.o); }
public unsafe static object RhBoxAny(ref Hack_o_p data, EETypePtr pEEType) { EEType *ptrEEType = (EEType *)pEEType.ToPointer(); if (ptrEEType->IsValueType) { // HACK: we would really want to take the address of o here, // but the rules of the C# language don't let us do that, // so we arrive at the same result by taking the address of p // and going back one pointer-sized unit fixed(IntPtr *pData = &data.p) return(RhBox(pEEType, pData - 1)); } else { return(data.o); } }
static public unsafe bool RhBoxAndNullCheck(ref Hack_o_p data, EETypePtr pEEType) { EEType* ptrEEType = (EEType*)pEEType.ToPointer(); if (ptrEEType->IsValueType) return true; else return data.o != null; }
static public unsafe void RhArrayStoreCheckAny(object array, ref Hack_o_p data) { if (array == null) { return; } Debug.Assert(array.EEType->IsArray, "first argument must be an array"); EEType* arrayElemType = array.EEType->RelatedParameterType; if (arrayElemType->IsValueType) { return; } TypeCast.CheckArrayStore(array, data.o); }
static public unsafe void RhUnboxNullable(ref Hack_o_p data, EETypePtr pUnboxToEEType, Object obj) { EEType* ptrUnboxToEEType = (EEType*)pUnboxToEEType.ToPointer(); // HACK: we would really want to take the address of o here, // but the rules of the C# language don't let us do that, // so we arrive at the same result by taking the address of p // and going back one pointer-sized unit fixed (IntPtr* pData = &data.p) { if ((obj != null) && (obj.EEType != ptrUnboxToEEType->GetNullableType())) { IntPtr addr = ptrUnboxToEEType->GetAssociatedModuleAddress(); Exception e = EH.GetClasslibException(ExceptionIDs.InvalidCast, addr); BinderIntrinsics.TailCall_RhpThrowEx(e); } InternalCalls.RhUnbox(obj, pData - 1, ptrUnboxToEEType); } }
public unsafe static void RhUnboxAny(object o, ref Hack_o_p data, EETypePtr pUnboxToEEType) { EEType* ptrUnboxToEEType = (EEType*)pUnboxToEEType.ToPointer(); if (ptrUnboxToEEType->IsValueType) { // HACK: we would really want to take the address of o here, // but the rules of the C# language don't let us do that, // so we arrive at the same result by taking the address of p // and going back one pointer-sized unit fixed (IntPtr* pData = &data.p) { bool isValid = false; if (ptrUnboxToEEType->IsNullable) isValid = (o == null) || (o.EEType == ptrUnboxToEEType->GetNullableType()); else isValid = (o != null && o.EEType->CorElementType == ptrUnboxToEEType->CorElementType && TypeCast.IsInstanceOfClass(o, ptrUnboxToEEType) != null); if (!isValid) { // Throw the invalid cast exception defined by the classlib, using the input unbox EEType* // to find the correct classlib. ExceptionIDs exID = o == null ? ExceptionIDs.NullReference : ExceptionIDs.InvalidCast; IntPtr addr = ptrUnboxToEEType->GetAssociatedModuleAddress(); Exception e = EH.GetClasslibException(exID, addr); BinderIntrinsics.TailCall_RhpThrowEx(e); } InternalCalls.RhUnbox(o, pData - 1, ptrUnboxToEEType); } } else data.o = o; }
public unsafe static object RhBoxAny(ref Hack_o_p data, EETypePtr pEEType) { EEType* ptrEEType = (EEType*)pEEType.ToPointer(); if (ptrEEType->IsValueType) { // HACK: we would really want to take the address of o here, // but the rules of the C# language don't let us do that, // so we arrive at the same result by taking the address of p // and going back one pointer-sized unit fixed (IntPtr* pData = &data.p) return RhBox(pEEType, pData - 1); } else return data.o; }
public unsafe static void RhUnboxAny(object o, ref Hack_o_p data, EETypePtr pUnboxToEEType) { EEType* ptrUnboxToEEType = (EEType*)pUnboxToEEType.ToPointer(); if (ptrUnboxToEEType->IsValueType) { // HACK: we would really want to take the address of o here, // but the rules of the C# language don't let us do that, // so we arrive at the same result by taking the address of p // and going back one pointer-sized unit fixed (IntPtr* pData = &data.p) { bool isValid = false; if (ptrUnboxToEEType->IsNullable) isValid = (o == null) || TypeCast.AreTypesEquivalentInternal(o.EEType, ptrUnboxToEEType->NullableType); else if (o != null) { isValid = UnboxAnyTypeCompare(o.EEType, ptrUnboxToEEType); } if (!isValid) { // Throw the invalid cast exception defined by the classlib, using the input unbox EEType* // to find the correct classlib. ExceptionIDs exID = o == null ? ExceptionIDs.NullReference : ExceptionIDs.InvalidCast; throw ptrUnboxToEEType->GetClasslibException(exID); } InternalCalls.RhUnbox(o, pData - 1, ptrUnboxToEEType); } } else { if (o == null || (TypeCast.IsInstanceOf(o, ptrUnboxToEEType) != null)) { data.o = o; } else { throw ptrUnboxToEEType->GetClasslibException(ExceptionIDs.InvalidCast); } } }