コード例 #1
0
ファイル: safebuffer.cs プロジェクト: wwkkww1983/ZJCredit
        public unsafe T Read <T>(ulong byteOffset) 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();
            T structure;

            try
            {
                this.DangerousAddRef(ref success);
                SafeBuffer.GenericPtrToStructure <T>(ptr, out structure, sizeofT);
            }
            finally
            {
                if (success)
                {
                    this.DangerousRelease();
                }
            }
            return(structure);
        }
コード例 #2
0
        public unsafe T Read <T>(ulong byteOffset) 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();
            T result;

            try
            {
                base.DangerousAddRef(ref flag);
                SafeBuffer.GenericPtrToStructure <T>(ptr, out result, num);
            }
            finally
            {
                if (flag)
                {
                    base.DangerousRelease();
                }
            }
            return(result);
        }
コード例 #3
0
ファイル: safebuffer.cs プロジェクト: wwkkww1983/ZJCredit
        public unsafe void ReadArray <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.GenericPtrToStructure <T>(ptr + (long)num * (long)index1, out array[index1 + index], sizeofT);
                }
            }
            finally
            {
                if (success)
                {
                    this.DangerousRelease();
                }
            }
        }