當前位置: 首頁>>代碼示例>>C#>>正文


C# StringWriter.CopyTo方法代碼示例

本文整理匯總了C#中System.IO.StringWriter.CopyTo方法的典型用法代碼示例。如果您正苦於以下問題:C# StringWriter.CopyTo方法的具體用法?C# StringWriter.CopyTo怎麽用?C# StringWriter.CopyTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.StringWriter的用法示例。


在下文中一共展示了StringWriter.CopyTo方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: OnlyUsesBufferUpToSize

        public void OnlyUsesBufferUpToSize(int count)
        {
            string text = new string('a', count);
            Byte[] textInBytes = Encoding.UTF8.GetBytes(text);

            Mock<StreamWriter> mock;

            Byte[] buffer = new Byte[textInBytes.Length + 100];

            using (MemoryStream stream = new MemoryStream(buffer))
            {
                StringWriter writer = new StringWriter();

                mock = new Mock<StreamWriter>(MockBehavior.Strict, stream) { CallBase = true };
                mock.Setup(sw => sw.Write(It.IsAny<char[]>(),
                                          It.IsAny<int>(),
                                          It.Is<int>(c => c == StringWriterExtensions.BufferSize ||
                                                          c == textInBytes.Length % StringWriterExtensions.BufferSize)))
                    .Verifiable();

                StreamWriter outputWriter = mock.Object;
                writer.Write(text);
                writer.CopyTo(outputWriter);

                mock.Verify();
            }
        }
開發者ID:ahmetgoktas,項目名稱:aspnetwebstack,代碼行數:27,代碼來源:StringWriterExtensionsTest.cs

示例2: CopiesResult

        public void CopiesResult()
        {
            // Note that a preable is not expected on the generated stream.
            string text = "Hello world";
            Byte[] textInBytes = Encoding.UTF8.GetBytes(text);
            string outputText;

            Byte[] buffer = new Byte[1024];

            using (MemoryStream stream = new MemoryStream(buffer))
            using (StringWriter writer = new StringWriter())
            using (StreamWriter outputWriter = new StreamWriter(stream))
            {
                writer.Write(text);
                writer.CopyTo(outputWriter);

                outputText = writer.ToString();
            }

            Assert.Equal(text, outputText, StringComparer.Ordinal);

            for (int i = 0; i < textInBytes.Length; i++)
            {
                Assert.Equal(textInBytes[i], buffer[i]);
            }
        }
開發者ID:ahmetgoktas,項目名稱:aspnetwebstack,代碼行數:26,代碼來源:StringWriterExtensionsTest.cs

示例3: ProperlyCopiesLargeSetsOfText

        public void ProperlyCopiesLargeSetsOfText(int count)
        {
            // The char א turns into a two byte sequence so we end up with a 
            // 7 byte sequence that is not a divider or 1024.
            string text = string.Join(string.Empty, Enumerable.Repeat("abcdeא", count));

            Byte[] textInBytes = Encoding.UTF8.GetBytes(text);
            string outputText;

            Byte[] buffer = new Byte[textInBytes.Length + 100];

            using (MemoryStream stream = new MemoryStream(buffer))
            using (StringWriter writer = new StringWriter())
            {
                using (StreamWriter outputWriter = new StreamWriter(stream))
                {
                    writer.Write(text);
                    writer.CopyTo(outputWriter);

                    outputText = writer.ToString();
                }
            }

            Assert.Equal(text, outputText, StringComparer.Ordinal);

            for (int i = 0; i < textInBytes.Length; i++)
            {
                Assert.Equal(textInBytes[i], buffer[i]);
            }
        }
開發者ID:ahmetgoktas,項目名稱:aspnetwebstack,代碼行數:30,代碼來源:StringWriterExtensionsTest.cs


注:本文中的System.IO.StringWriter.CopyTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。