Skip to content

Commit e1d6e46

Browse files
Merge pull request #34 from GabrielMarquezMatte/develop
Refactor CSV and Excel enumerators for improved performance and clarity
2 parents bf6a94d + 2d7620f commit e1d6e46

53 files changed

Lines changed: 977 additions & 1172 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Directory.Build.props

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<Project>
22
<PropertyGroup>
3+
<LangVersion>latest</LangVersion>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
<Deterministic>true</Deterministic>
37
<AnalysisLevel>latest</AnalysisLevel>
48
<AnalysisMode>All</AnalysisMode>
59
<!-- <TreatWarningsAsErrors>true</TreatWarningsAsErrors> -->
@@ -19,8 +23,6 @@
1923
</PropertyGroup>
2024
<PropertyGroup Condition="'$(Configuration)'=='Release'">
2125
<Optimize>true</Optimize>
22-
<DebugType>none</DebugType>
23-
<DebugSymbols>false</DebugSymbols>
2426
<DefineConstants>$(DefineConstants.Replace("DEBUG;", ""))</DefineConstants>
2527
<DefineConstants>$(DefineConstants.Replace("TRACE;", ""))</DefineConstants>
2628
</PropertyGroup>
@@ -82,4 +84,4 @@
8284
<PrivateAssets>all</PrivateAssets>
8385
</PackageReference>
8486
</ItemGroup>
85-
</Project>
87+
</Project>

src/ExcelReader.Core/ExcelEpoch.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace ExcelReader.Core
2+
{
3+
// Excel reserves serial 60 for the fictitious 1900-02-29; OADate does not. Keep this conversion
4+
// shared so the binary writers and the public Cell date reader cannot drift at the boundary.
5+
internal static class ExcelEpoch
6+
{
7+
internal static double SerialToOADate(double serial, bool date1904)
8+
{
9+
if (date1904)
10+
{
11+
return serial + 1462.0;
12+
}
13+
return serial switch
14+
{
15+
< 60.0 => serial + 1.0,
16+
60.0 => 60.0,
17+
_ => serial,
18+
};
19+
}
20+
21+
internal static double OADateToSerial(double oadate, bool date1904)
22+
{
23+
double serial = oadate;
24+
if (date1904)
25+
{
26+
serial -= 1462.0;
27+
}
28+
else if (oadate < 61.0)
29+
{
30+
serial--;
31+
}
32+
if (serial < 0)
33+
{
34+
throw new ArgumentOutOfRangeException(nameof(oadate), "Dates before the workbook epoch cannot be written to Excel.");
35+
}
36+
return serial;
37+
}
38+
}
39+
}

src/ExcelReader.Core/ExcelReader.Core.csproj

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

33
<PropertyGroup>
44
<TargetFrameworks>net10.0;net8.0</TargetFrameworks>
5-
<LangVersion>latest</LangVersion>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
<Nullable>enable</Nullable>
5+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
86

97
<!-- Ship XML docs (members without a doc comment do not warn). -->
108
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -34,7 +32,6 @@
3432
<DebugType>portable</DebugType>
3533
<PublishRepositoryUrl>true</PublishRepositoryUrl>
3634
<EmbedUntrackedSources>true</EmbedUntrackedSources>
37-
<Deterministic>true</Deterministic>
3835
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
3936
</PropertyGroup>
4037

src/ExcelReader.Core/Parser/ExcelParser.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public ExcelEnumerable<T> Parse(XlsxReader reader)
3333

3434
[SuppressMessage("Usage", "VSTHRD200:Use \"Async\" suffix for async methods",
3535
Justification = "Synchronous entry point; the enumerable also implements IAsyncEnumerable, but ParseAsync is the async counterpart.")]
36-
public XlsExcelEnumerable<T> Parse(XlsReader reader)
36+
public ExcelEnumerable<T, XlsReader, XlsReader.Enumerator> Parse(XlsReader reader)
3737
{
3838
ArgumentNullException.ThrowIfNull(reader);
39-
return new XlsExcelEnumerable<T>(reader, _config);
39+
return new ExcelEnumerable<T, XlsReader, XlsReader.Enumerator>(reader, _config);
4040
}
4141

4242
[SuppressMessage("Usage", "VSTHRD200:Use \"Async\" suffix for async methods",
@@ -75,10 +75,10 @@ public ExcelEnumerable<T> ParseAsync(XlsxReader reader, CancellationToken ct = d
7575
return new ExcelEnumerable<T>(reader, _config, ct);
7676
}
7777

78-
public XlsExcelEnumerable<T> ParseAsync(XlsReader reader, CancellationToken ct = default)
78+
public ExcelEnumerable<T, XlsReader, XlsReader.Enumerator> ParseAsync(XlsReader reader, CancellationToken ct = default)
7979
{
8080
ArgumentNullException.ThrowIfNull(reader);
81-
return new XlsExcelEnumerable<T>(reader, _config, ct);
81+
return new ExcelEnumerable<T, XlsReader, XlsReader.Enumerator>(reader, _config, ct);
8282
}
8383

8484
public ExcelEnumerable<T, XlsbReader, XlsbReader.Enumerator> ParseAsync(XlsbReader reader, CancellationToken ct = default)

0 commit comments

Comments
 (0)