public static unsafe void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count) { if (src == null) throw new ArgumentNullException(nameof(src)); if (dst == null) throw new ArgumentNullException(nameof(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, nameof(src)); if (src != dst) { RuntimeImports.RhCorElementTypeInfo dstCorElementTypeInfo = dst.ElementEEType.CorElementTypeInfo; if (!dstCorElementTypeInfo.IsPrimitive) throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(dst)); uDstLen = ((nuint)dst.Length) << dstCorElementTypeInfo.Log2OfSize; } if (srcOffset < 0) throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, nameof(srcOffset)); if (dstOffset < 0) throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, nameof(dstOffset)); if (count < 0) throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, nameof(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 (byte* pSrc = &src.GetRawArrayData(), pDst = &dst.GetRawArrayData()) { Buffer.Memmove(pDst + dstOffset, pSrc + srcOffset, uCount); } }
public static unsafe void SetByte(Array array, int index, byte value) { // Is the array present? if (array == null) throw new ArgumentNullException(nameof(array)); // Is it of primitive types? if (!array.ElementEEType.IsPrimitive) throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(array)); // Is the index in valid range of the array? if (index < 0 || index >= _ByteLength(array)) throw new ArgumentOutOfRangeException(nameof(index)); Unsafe.Add(ref array.GetRawArrayData(), index) = value; }
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"); return Unsafe.Add(ref array.GetRawArrayData(), index); }