Skip to content

Commit ebf2aac

Browse files
Changed CsvConfiguration property ReadEmptyStringAsNull to ReadEmptyFieldsAsDefault for clarity
The original property has been obsoleted but left as a facade
1 parent 6645c68 commit ebf2aac

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎src/MiniExcel.Csv/CsvConfiguration.cs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ public class CsvConfiguration : MiniExcelBaseConfiguration
1111
public char Seperator { get; set; } = ',';
1212
public string NewLine { get; set; } = "\r\n";
1313
public bool ReadLineBreaksWithinQuotes { get; set; } = true;
14-
public bool ReadEmptyStringAsNull { get; set; } = false;
14+
15+
/// <summary>
16+
/// When set to true, empty fields will be converted to null when queried as strings,
17+
/// or to the default value of the corresponding mapped type. Default is false.
18+
/// </summary>
19+
public bool ReadEmptyFieldsAsDefault { get; set; } = false;
20+
21+
[Obsolete("Please use the ReadEmptyFieldsAsDefault property instead")]
22+
public bool ReadEmptyStringAsNull
23+
{
24+
get => ReadEmptyFieldsAsDefault;
25+
set => ReadEmptyFieldsAsDefault = value;
26+
}
1527

1628
/// <summary>
1729
/// When set to true, rows with fewer columns than the header are padded with default values

‎src/MiniExcel.Csv/CsvReader.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ internal CsvReader(Stream stream, IMiniExcelConfiguration? configuration, bool l
108108
// todo: can we find a way to remove the redundant cell conversions for CSV?
109109
var maxCol = (_config.FillMissingColumns ? headRows.Count : read.Length) - 1;
110110
var cell = ExpandoHelper.CreateEmptyByIndices(maxCol, 0);
111-
if (_config.ReadEmptyStringAsNull)
111+
if (_config.ReadEmptyFieldsAsDefault)
112112
{
113113
for (int i = 0; i <= read.Length - 1; i++)
114114
cell[CellReferenceConverter.GetAlphabeticalIndex(i)] = read[i] is var value and not "" ? value : null;

‎tests/MiniExcel.Csv.Tests/Issues/GithubIssuesTests.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ public void Issue979NoHeader()
695695
var csvConfig = new CsvConfiguration
696696
{
697697
AlwaysQuote = true,
698-
ReadEmptyStringAsNull = true
698+
ReadEmptyFieldsAsDefault = true
699699
};
700700

701701
var data = """

‎tests/MiniExcel.Csv.Tests/Main/MiniExcelCsvAsyncTests.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ await _csvExporter.ExportAsync(path, new[]
328328
Assert.Equal(string.Empty, rows[1].C2);
329329
}
330330

331-
var config = new CsvConfiguration { ReadEmptyStringAsNull = true };
331+
var config = new CsvConfiguration { ReadEmptyFieldsAsDefault = true };
332332
await using (var stream = File.OpenRead(path))
333333
{
334334
var rows = _csvImporter.Query<TestDto>(stream, configuration: config).ToList();

0 commit comments

Comments
 (0)