コード例 #1
0
 public void AppendLineFormat()
 {
     StringBuilder Builder = new StringBuilder();
     Builder.AppendLineFormat("This is test {0}", 1);
     Assert.Equal("This is test 1" + System.Environment.NewLine, Builder.ToString());
     Builder.Clear();
     Builder.AppendLineFormat("Test {0}", 2)
         .AppendLineFormat("And {0}", 3);
     Assert.Equal("Test 2" + System.Environment.NewLine + "And 3" + System.Environment.NewLine, Builder.ToString());
 }
コード例 #2
0
ファイル: ArchivingTests.cs プロジェクト: sillsdev/FieldWorks
		public void StringBuilder_AppendLineFormat()
		{
			var A = "A";
			var B = "B";
			var C = "C";
			var format = "{0}{1}{2}";
			var delimiter = ";;";
			var expected = "ABC;;CBA;;BCA";

			var sb = new StringBuilder();
			sb.AppendLineFormat(format, new object[] { A, B, C }, delimiter);
			sb.AppendLineFormat(format, new object[] { C, B, A }, delimiter);
			sb.AppendLineFormat(format, new object[] { B, C, A }, delimiter);

			Assert.AreEqual(expected, sb.ToString());
		}
コード例 #3
0
        public static string ToJson(Dictionary<string, string> variables)
        {
            var builder = new StringBuilder();
            builder.AppendLine("{");
            var last = variables.Last().Key;
            foreach (var variable in variables)
            {
                var isLast = (variable.Key == last);
                int value;
                if (int.TryParse(variable.Value, out value))
                    builder.AppendLineFormat("  \"{0}\":{1}{2}", variable.Key, value, isLast ? string.Empty : ",");
                else
                    builder.AppendLineFormat("  \"{0}\":\"{1}\"{2}", variable.Key, variable.Value, isLast ? string.Empty : ",");
            }

            builder.Append("}");
            return builder.ToString();
        }
コード例 #4
0
        public static string ToJson(VersionVariables variables)
        {
            var builder = new StringBuilder();
            builder.AppendLine("{");
            var last = variables.Last().Key;
            foreach (var variable in variables)
            {
                var isLast = (variable.Key == last);
                int value;
                if (int.TryParse(variable.Value, out value) && variable.Value[0] != '0') // preserve leading zeros for padding
                    builder.AppendLineFormat("  \"{0}\":{1}{2}", variable.Key, value, isLast ? string.Empty : ",");
                else
                    builder.AppendLineFormat("  \"{0}\":\"{1}\"{2}", variable.Key, variable.Value, isLast ? string.Empty : ",");
            }

            builder.Append("}");
            return builder.ToString();
        }
コード例 #5
0
ファイル: SQLProfiler.cs プロジェクト: jerrymds/Concord
 /// <summary>
 /// Outputs the profiler information as an HTML table
 /// </summary>
 /// <returns>Table containing profiler information</returns>
 public override string ToHTML()
 {
     CompileData();
     StringBuilder Builder = new StringBuilder();
     Builder.AppendFormat(CultureInfo.InvariantCulture, "<tr><td>{0}</td><td>", CalledFrom);
     Builder.AppendFormat(CultureInfo.InvariantCulture, "{0}</td><td>{1}ms</td><td>{2}ms</td><td>{3}ms</td><td>{4}ms</td><td>{5}</td></tr>", Query, Times.Sum(), Times.Max(), Times.Min(), string.Format(CultureInfo.InvariantCulture, "{0:0.##}", Times.Average()), Times.Count);
     foreach (Profiler Child in Children)
     {
         Builder.AppendLineFormat(Child.ToHTML());
     }
     return Builder.ToString();
 }