当前位置: 首页>>代码示例>>C#>>正文


C# ArgumentException.SetErrorCode方法代码示例

本文整理汇总了C#中ArgumentException.SetErrorCode方法的典型用法代码示例。如果您正苦于以下问题:C# ArgumentException.SetErrorCode方法的具体用法?C# ArgumentException.SetErrorCode怎么用?C# ArgumentException.SetErrorCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArgumentException的用法示例。


在下文中一共展示了ArgumentException.SetErrorCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteAsync

        public IAsyncOperationWithProgress<UInt32, UInt32> WriteAsync(IBuffer buffer)
        {
            if (buffer == null)
            {
                // Mapped to E_POINTER.
                throw new ArgumentNullException("buffer");
            }

            if (buffer.Capacity < buffer.Length)
            {
                ArgumentException ex = new ArgumentException(SR.Argument_BufferLengthExceedsCapacity);
                ex.SetErrorCode(HResults.E_INVALIDARG);
                throw ex;
            }

            // Commented due to a reported CCRewrite bug. Should uncomment when fixed:
            //Contract.Ensures(Contract.Result<IAsyncOperationWithProgress<UInt32, UInt32>>() != null);
            //Contract.EndContractBlock();

            Stream str = EnsureNotDisposed();
            return StreamOperationsImplementation.WriteAsync_AbstractStream(str, buffer);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:22,代码来源:NetFxToWinRtStreamAdapter.cs

示例2: Seek

        public void Seek(UInt64 position)
        {
            if (position > Int64.MaxValue)
            {
                ArgumentException ex = new ArgumentException(SR.IO_CannotSeekBeyondInt64MaxValue);
                ex.SetErrorCode(HResults.E_INVALIDARG);
                throw ex;
            }

            // Commented due to a reported CCRewrite bug. Should uncomment when fixed:
            //Contract.EndContractBlock();

            Stream str = EnsureNotDisposed();
            Int64 pos = unchecked((Int64)position);

            Debug.Assert(str != null);
            Debug.Assert(str.CanSeek, "The underlying str is expected to support Seek, but it does not.");
            Debug.Assert(0 <= pos && pos <= Int64.MaxValue, "Unexpected pos=" + pos + ".");

            str.Seek(pos, SeekOrigin.Begin);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:21,代码来源:NetFxToWinRtStreamAdapter.cs

示例3: ReadAsync

        public IAsyncOperationWithProgress<IBuffer, UInt32> ReadAsync(IBuffer buffer, UInt32 count, InputStreamOptions options)
        {
            if (buffer == null)
            {
                // Mapped to E_POINTER.
                throw new ArgumentNullException("buffer");
            }

            if (count < 0 || Int32.MaxValue < count)
            {
                ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException("count");
                ex.SetErrorCode(HResults.E_INVALIDARG);
                throw ex;
            }

            if (buffer.Capacity < count)
            {
                ArgumentException ex = new ArgumentException(SR.Argument_InsufficientBufferCapacity);
                ex.SetErrorCode(HResults.E_INVALIDARG);
                throw ex;
            }

            if (!(options == InputStreamOptions.None || options == InputStreamOptions.Partial || options == InputStreamOptions.ReadAhead))
            {
                ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException("options",
                                                                                 SR.ArgumentOutOfRange_InvalidInputStreamOptionsEnumValue);
                ex.SetErrorCode(HResults.E_INVALIDARG);
                throw ex;
            }

            // Commented due to a reported CCRewrite bug. Should uncomment when fixed:
            //Contract.Ensures(Contract.Result<IAsyncOperationWithProgress<IBuffer, UInt32>>() != null);
            //Contract.EndContractBlock();

            Stream str = EnsureNotDisposed();

            IAsyncOperationWithProgress<IBuffer, UInt32> readAsyncOperation;
            switch (_readOptimization)
            {
                case StreamReadOperationOptimization.MemoryStream:
                    readAsyncOperation = StreamOperationsImplementation.ReadAsync_MemoryStream(str, buffer, count);
                    break;

                case StreamReadOperationOptimization.AbstractStream:
                    readAsyncOperation = StreamOperationsImplementation.ReadAsync_AbstractStream(str, buffer, count, options);
                    break;

                // Use this pattern to add more optimisation options if necessary:
                //case StreamReadOperationOptimization.XxxxStream:
                //    readAsyncOperation = StreamOperationsImplementation.ReadAsync_XxxxStream(str, buffer, count, options);
                //    break;

                default:
                    Debug.Assert(false, "We should never get here. Someone forgot to handle an input stream optimisation option.");
                    readAsyncOperation = null;
                    break;
            }

            return readAsyncOperation;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:60,代码来源:NetFxToWinRtStreamAdapter.cs


注:本文中的ArgumentException.SetErrorCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。