Exemplo n.º 1
0
        public string Format <T0>(T0 arg0)
        {
            var builder = new DefaultInterpolatedStringHandler(2, 1, CultureInfo.InvariantCulture);

            builder.AppendLiteral(_formatSegments[0]);
            FormatArgument(ref builder, arg0, _valueAlignments[0], _valueFormats[0]);
            builder.AppendLiteral(_formatSegments[1]);
            return(builder.ToString());
        }
Exemplo n.º 2
0
 private static void FormatArgument <T>(ref DefaultInterpolatedStringHandler builder, T arg, int?alignment, string?format)
 {
     if (arg is null)
     {
         builder.AppendLiteral(NullValue);
     }
     else
     {
         if (alignment.HasValue && format is not null)
         {
             builder.AppendFormatted <T>(arg, alignment.GetValueOrDefault(), format);
         }
         else if (alignment.HasValue)
         {
             builder.AppendFormatted <T>(arg, alignment.GetValueOrDefault());
         }
         else if (format is not null)
         {
             builder.AppendFormatted <T>(arg, format);
         }
         else
         {
             builder.AppendFormatted <T>(arg);
         }
     }
 }
        public void ToStringAndClear_Clears()
        {
            DefaultInterpolatedStringHandler handler = new DefaultInterpolatedStringHandler(0, 0);

            handler.AppendLiteral("hi");
            Assert.Equal("hi", handler.ToStringAndClear());
            Assert.Equal(string.Empty, handler.ToStringAndClear());
        }
        public void ToString_DoesntClear()
        {
            DefaultInterpolatedStringHandler handler = new DefaultInterpolatedStringHandler(0, 0);

            handler.AppendLiteral("hi");
            for (int i = 0; i < 3; i++)
            {
                Assert.Equal("hi", handler.ToString());
            }
            Assert.Equal("hi", handler.ToStringAndClear());
        }
        public void AppendLiteral()
        {
            var expected = new StringBuilder();
            DefaultInterpolatedStringHandler actual = new DefaultInterpolatedStringHandler(0, 0);

            foreach (string s in new[] { "", "a", "bc", "def", "this is a long string", "!" })
            {
                expected.Append(s);
                actual.AppendLiteral(s);
            }

            Assert.Equal(expected.ToString(), actual.ToStringAndClear());
        }
Exemplo n.º 6
0
        public string Format <T0, T1, T2, T3, T4, T5>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
        {
            var builder = new DefaultInterpolatedStringHandler(7, 6, CultureInfo.InvariantCulture);

            builder.AppendLiteral(_formatSegments[0]);
            FormatArgument(ref builder, arg0, _valueAlignments[0], _valueFormats[0]);
            builder.AppendLiteral(_formatSegments[1]);
            FormatArgument(ref builder, arg1, _valueAlignments[1], _valueFormats[1]);
            builder.AppendLiteral(_formatSegments[2]);
            FormatArgument(ref builder, arg2, _valueAlignments[2], _valueFormats[2]);
            builder.AppendLiteral(_formatSegments[3]);
            FormatArgument(ref builder, arg3, _valueAlignments[3], _valueFormats[3]);
            builder.AppendLiteral(_formatSegments[4]);
            FormatArgument(ref builder, arg4, _valueAlignments[4], _valueFormats[4]);
            builder.AppendLiteral(_formatSegments[5]);
            FormatArgument(ref builder, arg5, _valueAlignments[5], _valueFormats[5]);
            builder.AppendLiteral(_formatSegments[6]);
            return(builder.ToString());
        }
 public void AppendLiteral(string value)
 {
     _innerHandler.AppendLiteral(value);
 }