public static unsafe byte GetByte(Array array, int index) { // Is the array present? if (array == null) { throw new ArgumentNullException("array"); } // Is it of primitive types? if (!array.ElementEEType.IsPrimitive) { throw new ArgumentException(SR.Arg_MustBePrimArray, "array"); } // Is the index in valid range of the array? if (index < 0 || index >= _ByteLength(array)) { throw new ArgumentOutOfRangeException("index"); fixed(IntPtr *pObj = &array.m_pEEType) { byte *pByte = (byte *)Array.GetAddrOfPinnedArrayFromEETypeField(pObj) + index; return(*pByte); } }
public static unsafe void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count) { if (src == null) { throw new ArgumentNullException("src"); } if (dst == null) { throw new ArgumentNullException("dst"); } RuntimeImports.RhCorElementTypeInfo srcCorElementTypeInfo = src.ElementEEType.CorElementTypeInfo; nuint uSrcLen = ((nuint)src.Length) << srcCorElementTypeInfo.Log2OfSize; nuint uDstLen = uSrcLen; if (!srcCorElementTypeInfo.IsPrimitive) { throw new ArgumentException(SR.Arg_MustBePrimArray, "src"); } if (src != dst) { RuntimeImports.RhCorElementTypeInfo dstCorElementTypeInfo = dst.ElementEEType.CorElementTypeInfo; if (!dstCorElementTypeInfo.IsPrimitive) { throw new ArgumentException(SR.Arg_MustBePrimArray, "dst"); } uDstLen = ((nuint)dst.Length) << dstCorElementTypeInfo.Log2OfSize; } if (srcOffset < 0) { throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, "srcOffset"); } if (dstOffset < 0) { throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, "dstOffset"); } if (count < 0) { throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, "count"); } nuint uCount = (nuint)count; if (uSrcLen < ((nuint)srcOffset) + uCount) { throw new ArgumentException(SR.Argument_InvalidOffLen); } if (uDstLen < ((nuint)dstOffset) + uCount) { throw new ArgumentException(SR.Argument_InvalidOffLen); } if (uCount == 0) { return; fixed(IntPtr *pSrcObj = &src.m_pEEType, pDstObj = &dst.m_pEEType) { byte *pSrc = (byte *)Array.GetAddrOfPinnedArrayFromEETypeField(pSrcObj) + srcOffset; byte *pDst = (byte *)Array.GetAddrOfPinnedArrayFromEETypeField(pDstObj) + dstOffset; Buffer.Memmove(pDst, pSrc, uCount); } }