forked from axuno/SmartFormat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmart.cs
More file actions
105 lines (88 loc) · 2.38 KB
/
Smart.cs
File metadata and controls
105 lines (88 loc) · 2.38 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using SmartFormat.Core.Extensions;
using SmartFormat.Core.Settings;
using SmartFormat.Extensions;
namespace SmartFormat
{
/// <summary>
/// This class holds a Default instance of the SmartFormatter.
/// The default instance has all extensions registered.
/// </summary>
public static class Smart
{
#region: Smart.Format :
public static string Format(string format, params object[] args)
{
return Default.Format(format, args);
}
public static string Format(IFormatProvider provider, string format, params object[] args)
{
return Default.Format(provider, format, args);
}
#endregion
#region: Overloads - Just to match the signature of String.Format, and allow support for programming languages that don't support "params" :
public static string Format(string format, object arg0, object arg1, object arg2)
{
return Format(format, new object[] { arg0, arg1, arg2 });
}
public static string Format(string format, object arg0, object arg1)
{
return Format(format, new object[] { arg0, arg1 });
}
public static string Format(string format, object arg0)
{
return Format(format, new object[] { arg0 });
}
#endregion
#region: Default formatter :
private static SmartFormatter _default;
public static SmartFormatter Default
{
get
{
if (_default == null)
_default = CreateDefaultSmartFormat();
return _default;
}
set
{
_default = value;
}
}
public static SmartFormatter CreateDefaultSmartFormat()
{
// Register all default extensions here:
var result = new SmartFormatter();
// Add all extensions:
// Note, the order is important; the extensions
// will be executed in this order:
var listFormatter = new ListFormatter(result);
result.AddExtensions(
(ISource)listFormatter,
new ReflectionSource(result),
new DictionarySource(result),
// These default extensions reproduce the String.Format behavior:
new DefaultSource(result)
);
result.AddExtensions(
(IFormatter)listFormatter,
new PluralLocalizationFormatter("en"),
new ConditionalFormatter(),
new TimeFormatter("en"),
new DefaultFormatter()
);
return result;
}
#endregion
#region: Settings :
private static SmartSettings _settings;
public static SmartSettings Settings
{
get
{
return _settings ?? (_settings = new SmartSettings());
}
}
#endregion
}
}