src/dotnet/System.Array.c
tAsyncCall* System_Array_Internal_SetValue(PTR pThis_, PTR pParams, PTR pReturnValue) {
	tSystemArray *pArray = (tSystemArray*)pThis_;
	tMD_TypeDef *pArrayType, *pObjType;
	U32 index, elementSize;
	HEAP_PTR obj;
	tMD_TypeDef *pElementType;
	PTR pElement;

	pArrayType = Heap_GetType(pThis_);
	obj = ((HEAP_PTR*)pParams)[0];
	pObjType = Heap_GetType(obj);
	pElementType = pArrayType->pArrayElementType;
	// Check to see if the Type is ok to put in the array
	if (!(Type_IsAssignableFrom(pElementType, pObjType) ||
		(pElementType->pGenericDefinition == types[TYPE_SYSTEM_NULLABLE] &&
		pElementType->ppClassTypeArgs[0] == pObjType))) {
		// Can't be done
		*(U32*)pReturnValue = 0;
		return NULL;
	}

	index = ((U32*)pParams)[1];

#if defined(WIN32) && defined(_DEBUG)
	// Do a bounds-check
	if (index >= pArray->length) {
		printf("[Array] Internal_SetValue() Bounds-check failed\n");
		__debugbreak();
	}
#endif

	elementSize = pElementType->arrayElementSize;
	pElement = pArray->elements + elementSize * index;
	if (pElementType->isValueType) {
		if (pElementType->pGenericDefinition == types[TYPE_SYSTEM_NULLABLE]) {
			// Nullable type, so treat specially
			if (obj == NULL) {
				memset(pElement, 0, elementSize);
			} else {
				*(U32*)pElement = 1;
				memcpy(pElement + 4, obj, elementSize - 4);
			}
		} else {
			// Get the value out of the box
			memcpy(pElement, obj, elementSize);
		}
	} else {
		// This must be a reference type, so it must be 32-bits wide
		*(HEAP_PTR*)pElement = obj;
	}
	*(U32*)pReturnValue = 1;

	return NULL;
}
// Value-types will be boxed
Value-types will be boxed
Value - types will be boxed
tAsyncCall* System_Array_Internal_SetValue(PTR pThis_, PTR pParams, PTR pReturnValue) {
	tSystemArray *pArray = (tSystemArray*)pThis_;
	tMD_TypeDef *pArrayType, *pObjType;
	U32 index, elementSize;
	HEAP_PTR obj;
	tMD_TypeDef *pElementType;
	PTR pElement;
	pArrayType = Heap_GetType(pThis_);
	obj = ((HEAP_PTR*)pParams)[0];
	pObjType = Heap_GetType(obj);
	pElementType = pArrayType->pArrayElementType;
	if (!(Type_IsAssignableFrom(pElementType, pObjType) ||
		(pElementType->pGenericDefinition == types[TYPE_SYSTEM_NULLABLE] &&
		pElementType->ppClassTypeArgs[0] == pObjType))) {
		*(U32*)pReturnValue = 0;
		return NULL;
	}
	index = ((U32*)pParams)[1];
#if defined(WIN32) && defined(_DEBUG)
	if (index >= pArray->length) {
		printf("[Array] Internal_SetValue() Bounds-check failed\n");
		__debugbreak();
	}
#endif
	elementSize = pElementType->arrayElementSize;
	pElement = pArray->elements + elementSize * index;
	if (pElementType->isValueType) {
		if (pElementType->pGenericDefinition == types[TYPE_SYSTEM_NULLABLE]) {
			if (obj == NULL) {
				memset(pElement, 0, elementSize);
			} else {
				*(U32*)pElement = 1;
				memcpy(pElement + 4, obj, elementSize - 4);
			}
		} else {
			memcpy(pElement, obj, elementSize);
		}
	} else {
		*(HEAP_PTR*)pElement = obj;
	}
	*(U32*)pReturnValue = 1;
	return NULL;
}
tAsyncCall * System_Array_Internal_SetValue ( PTR pThis_ , PTR pParams , PTR pReturnValue ) { tSystemArray * pArray = ( tSystemArray * ) pThis_ ; tMD_TypeDef * pArrayType , * pObjType ; U32 index , elementSize ; HEAP_PTR obj ; tMD_TypeDef * pElementType ; PTR pElement ; pArrayType = Heap_GetType ( pThis_ ) ; obj = ( ( HEAP_PTR * ) pParams ) [ 0 ] ; pObjType = Heap_GetType ( obj ) ; pElementType = pArrayType -> pArrayElementType ; if ( ! ( Type_IsAssignableFrom ( pElementType , pObjType ) || ( pElementType -> pGenericDefinition == types [ TYPE_SYSTEM_NULLABLE ] && pElementType -> ppClassTypeArgs [ 0 ] == pObjType ) ) ) { * ( U32 * ) pReturnValue = 0 ; return NULL ; } index = ( ( U32 * ) pParams ) [ 1 ] ; #if defined ( WIN32 ) && defined ( _DEBUG ) if ( index >= pArray -> length ) { printf ( " \n " ) ; __debugbreak ( ) ; } #endif elementSize = pElementType -> arrayElementSize ; pElement = pArray -> elements + elementSize * index ; if ( pElementType -> isValueType ) { if ( pElementType -> pGenericDefinition == types [ TYPE_SYSTEM_NULLABLE ] ) { if ( obj == NULL ) { memset ( pElement , 0 , elementSize ) ; } else { * ( U32 * ) pElement = 1 ; memcpy ( pElement + 4 , obj , elementSize - 4 ) ; } } else { memcpy ( pElement , obj , elementSize ) ; } } else { * ( HEAP_PTR * ) pElement = obj ; } * ( U32 * ) pReturnValue = 1 ; return NULL ; }
Value-types will be boxed
Value - types will be boxed
// Check to see if the Type is ok to put in the array // Can't be done // Do a bounds-check // Nullable type, so treat specially // Get the value out of the box // This must be a reference type, so it must be 32-bits wide