Skip to content

Commit dae2d92

Browse files
committed
Backported XML comments + minor tweaks from ExcelDataReader
1 parent 862cff6 commit dae2d92

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

src/ExcelNumberFormat/ExcelNumberFormat.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>net20;netstandard1.0</TargetFrameworks>
5+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
56
</PropertyGroup>
67

78
</Project>

src/ExcelNumberFormat/NumberFormat.cs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44

55
namespace ExcelNumberFormat
66
{
7+
/// <summary>
8+
/// Parse ECMA-376 number format strings and format values like Excel and other spreadsheet softwares.
9+
/// </summary>
710
public class NumberFormat
811
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="NumberFormat"/> class.
14+
/// </summary>
15+
/// <param name="formatString">The number format string.</param>
916
public NumberFormat(string formatString)
1017
{
1118
var sections = Parser.ParseSections(formatString, out bool syntaxError);
@@ -16,35 +23,43 @@ public NumberFormat(string formatString)
1623
if (IsValid)
1724
{
1825
Sections = sections;
26+
IsDateTimeFormat = Evaluator.GetFirstSection(Sections, SectionType.Date) != null;
27+
IsTimeSpanFormat = Evaluator.GetFirstSection(Sections, SectionType.Duration) != null;
1928
}
2029
else
2130
{
2231
Sections = new List<Section>();
2332
}
2433
}
2534

35+
/// <summary>
36+
/// Gets a value indicating whether the number format string is valid.
37+
/// </summary>
2638
public bool IsValid { get; }
2739

40+
/// <summary>
41+
/// Gets the number format string.
42+
/// </summary>
2843
public string FormatString { get; }
2944

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; }
3149

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; }
3954

40-
public bool IsTimeSpanFormat
41-
{
42-
get
43-
{
44-
return Evaluator.GetFirstSection(Sections, SectionType.Duration) != null;
45-
}
46-
}
55+
internal List<Section> Sections { get; }
4756

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>
4863
public string Format(object value, CultureInfo culture)
4964
{
5065
if (!IsValid || string.IsNullOrEmpty(FormatString))

0 commit comments

Comments
 (0)