public unsafe void Write <T>(ulong byteOffset, T value) where T : struct { if (this._numBytes == SafeBuffer.Uninitialized) { throw SafeBuffer.NotInitialized(); } uint sizeofT = Marshal.SizeOfType(typeof(T)); byte *ptr = (byte *)((IntPtr)(void *)this.handle + (IntPtr)byteOffset); this.SpaceCheck(ptr, (ulong)sizeofT); bool success = false; RuntimeHelpers.PrepareConstrainedRegions(); try { this.DangerousAddRef(ref success); SafeBuffer.GenericStructureToPtr <T>(ref value, ptr, sizeofT); } finally { if (success) { this.DangerousRelease(); } } }
public unsafe void Write <T>(ulong byteOffset, T value) where T : struct { if (this._numBytes == SafeBuffer.Uninitialized) { throw SafeBuffer.NotInitialized(); } uint num = Marshal.SizeOfType(typeof(T)); byte *ptr = (byte *)((void *)this.handle) + byteOffset; this.SpaceCheck(ptr, (ulong)num); bool flag = false; RuntimeHelpers.PrepareConstrainedRegions(); try { base.DangerousAddRef(ref flag); SafeBuffer.GenericStructureToPtr <T>(ref value, ptr, num); } finally { if (flag) { base.DangerousRelease(); } } }
public unsafe void WriteArray <T>(ulong byteOffset, T[] array, int index, int count) where T : struct { if (array == null) { throw new ArgumentNullException("array", Environment.GetResourceString("ArgumentNull_Buffer")); } if (index < 0) { throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (count < 0) { throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (array.Length - index < count) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); } if (this._numBytes == SafeBuffer.Uninitialized) { throw SafeBuffer.NotInitialized(); } uint sizeofT = Marshal.SizeOfType(typeof(T)); uint num = Marshal.AlignedSizeOf <T>(); byte *ptr = (byte *)((IntPtr)(void *)this.handle + (IntPtr)byteOffset); this.SpaceCheck(ptr, checked ((ulong)((long)num * (long)count))); bool success = false; RuntimeHelpers.PrepareConstrainedRegions(); try { this.DangerousAddRef(ref success); for (int index1 = 0; index1 < count; ++index1) { SafeBuffer.GenericStructureToPtr <T>(ref array[index1 + index], ptr + (long)num * (long)index1, sizeofT); } } finally { if (success) { this.DangerousRelease(); } } }