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

	index = *(U32*)pParams;
	pArrayType = Heap_GetType(pThis_);
	pElementType = pArrayType->pArrayElementType;
	elementSize = pElementType->arrayElementSize;
	pElement = pArray->elements + elementSize * index;
	if (pElementType->isValueType) {
		// If it's a value-type, then box it
		HEAP_PTR boxedValue;
		if (pElementType->pGenericDefinition == types[TYPE_SYSTEM_NULLABLE]) {
			// Nullable type, so box specially
			if (*(U32*)pElement) {
				// Nullable has value
				boxedValue = Heap_AllocType(pElementType->ppClassTypeArgs[0]);
				// Don't copy the .hasValue part
				memcpy(boxedValue, pElement + 4, elementSize - 4);
			} else {
				// Nullable does not have value
				boxedValue = NULL;
			}
		} else {
			boxedValue = Heap_AllocType(pElementType);
			memcpy(boxedValue, pElement, elementSize);
		}
		*(HEAP_PTR*)pReturnValue = boxedValue;
	} else {
		// This must be a reference type, so it must be 32-bits wide
		*(U32*)pReturnValue = *(U32*)pElement;
	}

	return NULL;
}
// Must return a boxed version of value-types
Must return a boxed version of value-types
Must return a boxed version of value - types
tAsyncCall* System_Array_Internal_GetValue(PTR pThis_, PTR pParams, PTR pReturnValue) {
	tSystemArray *pArray = (tSystemArray*)pThis_;
	tMD_TypeDef *pArrayType;
	U32 index, elementSize;
	tMD_TypeDef *pElementType;
	PTR pElement;
	index = *(U32*)pParams;
	pArrayType = Heap_GetType(pThis_);
	pElementType = pArrayType->pArrayElementType;
	elementSize = pElementType->arrayElementSize;
	pElement = pArray->elements + elementSize * index;
	if (pElementType->isValueType) {
		HEAP_PTR boxedValue;
		if (pElementType->pGenericDefinition == types[TYPE_SYSTEM_NULLABLE]) {
			if (*(U32*)pElement) {
				boxedValue = Heap_AllocType(pElementType->ppClassTypeArgs[0]);
				memcpy(boxedValue, pElement + 4, elementSize - 4);
			} else {
				boxedValue = NULL;
			}
		} else {
			boxedValue = Heap_AllocType(pElementType);
			memcpy(boxedValue, pElement, elementSize);
		}
		*(HEAP_PTR*)pReturnValue = boxedValue;
	} else {
		*(U32*)pReturnValue = *(U32*)pElement;
	}
	return NULL;
}
tAsyncCall * System_Array_Internal_GetValue ( PTR pThis_ , PTR pParams , PTR pReturnValue ) { tSystemArray * pArray = ( tSystemArray * ) pThis_ ; tMD_TypeDef * pArrayType ; U32 index , elementSize ; tMD_TypeDef * pElementType ; PTR pElement ; index = * ( U32 * ) pParams ; pArrayType = Heap_GetType ( pThis_ ) ; pElementType = pArrayType -> pArrayElementType ; elementSize = pElementType -> arrayElementSize ; pElement = pArray -> elements + elementSize * index ; if ( pElementType -> isValueType ) { HEAP_PTR boxedValue ; if ( pElementType -> pGenericDefinition == types [ TYPE_SYSTEM_NULLABLE ] ) { if ( * ( U32 * ) pElement ) { boxedValue = Heap_AllocType ( pElementType -> ppClassTypeArgs [ 0 ] ) ; memcpy ( boxedValue , pElement + 4 , elementSize - 4 ) ; } else { boxedValue = NULL ; } } else { boxedValue = Heap_AllocType ( pElementType ) ; memcpy ( boxedValue , pElement , elementSize ) ; } * ( HEAP_PTR * ) pReturnValue = boxedValue ; } else { * ( U32 * ) pReturnValue = * ( U32 * ) pElement ; } return NULL ; }
Must return a boxed version of value-types
Must return a boxed version of value - types
// If it's a value-type, then box it // Nullable type, so box specially // Nullable has value // Don't copy the .hasValue part // Nullable does not have value // This must be a reference type, so it must be 32-bits wide