4
4
5
5
namespace ExcelNumberFormat
6
6
{
7
+ /// <summary>
8
+ /// Parse ECMA-376 number format strings and format values like Excel and other spreadsheet softwares.
9
+ /// </summary>
7
10
public class NumberFormat
8
11
{
12
+ /// <summary>
13
+ /// Initializes a new instance of the <see cref="NumberFormat"/> class.
14
+ /// </summary>
15
+ /// <param name="formatString">The number format string.</param>
9
16
public NumberFormat ( string formatString )
10
17
{
11
18
var sections = Parser . ParseSections ( formatString , out bool syntaxError ) ;
@@ -16,35 +23,43 @@ public NumberFormat(string formatString)
16
23
if ( IsValid )
17
24
{
18
25
Sections = sections ;
26
+ IsDateTimeFormat = Evaluator . GetFirstSection ( Sections , SectionType . Date ) != null ;
27
+ IsTimeSpanFormat = Evaluator . GetFirstSection ( Sections , SectionType . Duration ) != null ;
19
28
}
20
29
else
21
30
{
22
31
Sections = new List < Section > ( ) ;
23
32
}
24
33
}
25
34
35
+ /// <summary>
36
+ /// Gets a value indicating whether the number format string is valid.
37
+ /// </summary>
26
38
public bool IsValid { get ; }
27
39
40
+ /// <summary>
41
+ /// Gets the number format string.
42
+ /// </summary>
28
43
public string FormatString { get ; }
29
44
30
- internal List < Section > Sections { get ; }
45
+ /// <summary>
46
+ /// Gets a value indicating whether the format represents a DateTime
47
+ /// </summary>
48
+ public bool IsDateTimeFormat { get ; }
31
49
32
- public bool IsDateTimeFormat
33
- {
34
- get
35
- {
36
- return Evaluator . GetFirstSection ( Sections , SectionType . Date ) != null ;
37
- }
38
- }
50
+ /// <summary>
51
+ /// Gets a value indicating whether the format represents a TimeSpan
52
+ /// </summary>
53
+ public bool IsTimeSpanFormat { get ; }
39
54
40
- public bool IsTimeSpanFormat
41
- {
42
- get
43
- {
44
- return Evaluator . GetFirstSection ( Sections , SectionType . Duration ) != null ;
45
- }
46
- }
55
+ internal List < Section > Sections { get ; }
47
56
57
+ /// <summary>
58
+ /// Formats a value with this number format in a specified culture.
59
+ /// </summary>
60
+ /// <param name="value">The value to format.</param>
61
+ /// <param name="culture">The culture to use for formatting.</param>
62
+ /// <returns>The formatted string.</returns>
48
63
public string Format ( object value , CultureInfo culture )
49
64
{
50
65
if ( ! IsValid || string . IsNullOrEmpty ( FormatString ) )
0 commit comments