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


C# BufferedStream.Dispose方法代码示例

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


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

示例1: CopyToAsync_InvalidArguments_Throws

        public void CopyToAsync_InvalidArguments_Throws()
        {
            using (var s = new BufferedStream(new MemoryStream()))
            {
                // Null destination
                Assert.Throws<ArgumentNullException>("destination", () => { s.CopyToAsync(null); });

                // Buffer size out-of-range
                Assert.Throws<ArgumentOutOfRangeException>("bufferSize", () => { s.CopyToAsync(new MemoryStream(), 0); });
                Assert.Throws<ArgumentOutOfRangeException>("bufferSize", () => { s.CopyToAsync(new MemoryStream(), -1, CancellationToken.None); });

                // Copying to non-writable stream
                Assert.Throws<NotSupportedException>(() => { s.CopyToAsync(new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: true)); });

                // Copying to a non-writable and non-readable stream
                Assert.Throws<ObjectDisposedException>(() => { s.CopyToAsync(new WrappedMemoryStream(canRead: false, canWrite: false, canSeek: false)); });

                // Copying after disposing the buffer stream
                s.Dispose();
                Assert.Throws<ObjectDisposedException>(() => { s.CopyToAsync(new MemoryStream()); });
            }

            // Copying after disposing the underlying stream
            using (var ms = new MemoryStream())
            using (var s = new BufferedStream(ms))
            {
                ms.Dispose();
                Assert.Throws<ObjectDisposedException>(() => { s.CopyToAsync(new MemoryStream()); });
            }

            // Copying from a non-readable source
            using (var s = new BufferedStream(new WrappedMemoryStream(canRead: false, canWrite: true, canSeek: true)))
            {
                Assert.Throws<NotSupportedException>(() => { s.CopyToAsync(new MemoryStream()); });
            }
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:36,代码来源:BufferedStream.InvalidParameters.cs


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