Пример #1
0
        private static void PooledStringBuilder_Simple_Impl(StringBuilderPool pool)
        {
            for (var i = 0; i < 100; i++)
            {
                using var obj = i % 2 == 0 ? pool.New() : PooledStringBuilder.New(pool);

                var sb = obj.StringBuilder;

                Assert.AreEqual(0, sb.Length);

                sb.Append("qux foo bar baz");
            }
        }
        private static string GetJsonString(JToken token)
        {
            using var builder = s_pool.New();

            var sb = builder.StringBuilder;

            using var sw = new StringWriter(sb, CultureInfo.InvariantCulture);

            using var jtw = new JsonTextWriter(sw)
                  {
                      Formatting = Formatting.None
                  };

            token.WriteTo(jtw);

            return(sw.ToString());
        }