forked from axuno/SmartFormat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartExtensions.cs
More file actions
72 lines (60 loc) · 3.18 KB
/
SmartExtensions.cs
File metadata and controls
72 lines (60 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System.Text;
using SmartFormat.Core;
using SmartFormat.Core.Output;
namespace SmartFormat
{
public static class SmartExtensions
{
#region: StringBuilder :
/// <summary> Appends a formatted string, using the same semantics as Smart.Format. </summary>
/// <param name="sb">The StringBuilder that will be used for output</param>
/// <param name="format">The template that defines how the arguments are formatted</param>
/// <param name="args">A list of arguments to be used in formatting</param>
public static void AppendSmart(this StringBuilder sb, string format, params object[] args)
{
var output = new StringOutput(sb);
Smart.Default.FormatInto(output, format, args);
}
/// <summary> AppendLines a formatted string, using the same semantics as Smart.Format. </summary>
/// <param name="sb">The StringBuilder that will be used for output</param>
/// <param name="format">The template that defines how the arguments are formatted</param>
/// <param name="args">A list of arguments to be used in formatting</param>
public static void AppendLineSmart(this StringBuilder sb, string format, params object[] args)
{
sb.AppendSmart(format, args);
sb.AppendLine();
}
#endregion
#region: TextWriter :
/// <summary> Writes out a formatted string, using the same semantics as Smart.Format. </summary>
/// <param name="writer">The TextWriter that will be used for output</param>
/// <param name="format">The template that defines how the arguments are formatted</param>
/// <param name="args">A list of arguments to be used in formatting</param>
public static void WriteSmart(this System.IO.TextWriter writer, string format, params object[] args)
{
var output = new TextWriterOutput(writer);
Smart.Default.FormatInto(output, format, args);
}
#endregion
#region: String :
/// <summary> Formats the specified arguments using this string as a template. </summary>
/// <param name="format">The template that defines how the arguments are formatted</param>
/// <param name="args">A list of arguments to be used in formatting</param>
public static string FormatSmart(this string format, params object[] args)
{
return Smart.Format(format, args);
}
/// <summary> Formats the specified arguments using this string as a template.
/// Caches the parsing results for increased performance.
/// </summary>
/// <param name="format">The template that defines how the arguments are formatted</param>
/// <param name="args">A list of arguments to be used in formatting</param>
/// <param name="cache">Outputs an object that increases performance if the same format string is used repeatedly.</param>
public static string FormatSmart(this string format, ref FormatCache cache, params object[] args)
{
// With cache:
return Smart.Default.FormatWithCache(ref cache, format, args);
}
#endregion
}
}