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


C# StringWriter.WriteAsync方法代码示例

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


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

示例1: WithProxy

 public async void WithProxy()
 {
     var writer = new StringWriter();
     var printer = Proxy.CreateProxy<HelloWorldPrinter>(async invocation =>
     {
         await writer.WriteAsync("John says, \"");
         await invocation.Proceed();
         await writer.WriteAsync("\"");
         return null;
     });
     await printer.SayHello(writer);
     Assert.AreEqual("John says, \"Hello World!\"", writer.ToString());
 }
开发者ID:kswoll,项目名称:sexy-proxy,代码行数:13,代码来源:ReadMeTests.cs

示例2: MiscWritesAsync

        public static async Task MiscWritesAsync()
        {
            var sw = new StringWriter();
            await sw.WriteAsync('H');
            await sw.WriteAsync(new char[] { 'e', 'l', 'l', 'o', ' ' });
            await sw.WriteAsync("World!");

            Assert.Equal("Hello World!", sw.ToString());
        }
开发者ID:Corillian,项目名称:corefx,代码行数:9,代码来源:StringWriterTests.cs

示例3: FormatBodyStreamAsync

        /// <summary>
        ///   Formats the contents of an HTTP request or response body into a string.
        /// </summary>
        /// <param name="bodyStream"></param>
        /// <returns>
        ///   The request or response body stream to use (must replace the current stream).
        /// </returns>
        private async Task<string> FormatBodyStreamAsync(Stream bodyStream)
        {
            if ((bodyStream == null) || !bodyStream.CanRead || !bodyStream.CanSeek)
            {
                return string.Empty;
            }

            // Creo un vettore di caratteri usato come buffer temporaneo.
            var buffer = new char[512];

            // E' fondamentale che lo stream del body rimanga aperto.
            using (var bodyReader = new StreamReader(bodyStream, PortableEncoding.UTF8WithoutBOM, false, buffer.Length, true))
            using (var psb = _stringBuilderPool.GetObject())
            using (var stringWriter = new StringWriter(psb.StringBuilder, CultureInfo.InvariantCulture))
            {
                // Riporto all'inizio la posizione dello stream per poterlo copiare in una stringa.
                bodyStream.Position = 0;

                // Avvio il ciclo di lettura a blocchi.
                var readIndex = 0;
                var readChars = 0;
                do
                {
                    // Leggo un blocco di caratteri dallo stream.
                    readChars = await bodyReader.ReadBlockAsync(buffer, 0, buffer.Length);
                    readIndex += readChars;

                    // Scrivo i caratteri letti.
                    await stringWriter.WriteAsync(buffer, 0, readChars);
                } while (readChars == buffer.Length && readIndex < _settings.MaxLoggedBodyLength);

                // Riporto all'inizio la posizione dello stream per consentire agli altri di leggerlo.
                bodyStream.Position = 0;

                return stringWriter.ToString();
            }
        }
开发者ID:finsaspa,项目名称:Caravan,代码行数:44,代码来源:HttpLoggingMiddleware.cs


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