Skip to content

Commit 0bab56f

Browse files
committed
improve docs and param rename
1 parent 9aa991d commit 0bab56f

3 files changed

Lines changed: 35 additions & 15 deletions

File tree

RecordParser.Test/FileReaderTest.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -574,11 +574,12 @@ public record RegularCaseRecord(int Aaa, int Bbb, int Ccc, int Ddd);
574574

575575
[Theory]
576576
[InlineData("\"AAA\",\"BBB\",\"CCC\",\"DDD\"")]
577+
[InlineData("Aaa,Bbb,Ccc,Ddd")]
577578
[InlineData("AAA,BBB,CCC,DDD")]
578579
[InlineData("aaa,bbb,ccc,ddd")]
579580
[InlineData("AAA , BBB , CCC , DDD")]
580581
[InlineData("A_AA,B_BB,C_CC,D_DD")]
581-
public void Read_csv_file_with_header_in_different_case_should_automatic_bind_mapping(string header)
582+
public void Read_csv_file_with_autobind_should_match_header_case_insensitive(string header)
582583
{
583584
// Arrange
584585

@@ -614,15 +615,15 @@ public void Read_csv_file_with_header_in_different_case_should_automatic_bind_ma
614615

615616
// Act
616617

617-
var items = reader.ReadRecords<RegularCaseRecord>(readOptions, skipMismatchedColumns: false);
618+
var items = reader.ReadRecords<RegularCaseRecord>(readOptions, skipUnmatchedColumns: false);
618619

619620
// Assert
620621

621622
items.Should().BeEquivalentTo(expected, cfg => cfg.WithStrictOrdering());
622623
}
623624

624625
[Fact]
625-
public void Read_csv_file_with_header_should_automatic_bind_support_additional_configuration()
626+
public void Read_csv_file_with_autobind_should_support_additional_configuration()
626627
{
627628
// Arrange
628629

@@ -658,7 +659,7 @@ public void Read_csv_file_with_header_should_automatic_bind_support_additional_c
658659

659660
// Act
660661

661-
var items = reader.ReadRecords<RegularCaseRecord>(readOptions, false, builder =>
662+
var items = reader.ReadRecords<RegularCaseRecord>(readOptions, skipUnmatchedColumns: false, builder =>
662663
builder.DefaultTypeConvert(x => int.Parse(x) * 10));
663664

664665
// Assert
@@ -667,7 +668,7 @@ public void Read_csv_file_with_header_should_automatic_bind_support_additional_c
667668
}
668669

669670
[Fact]
670-
public void Read_csv_file_with_header_containing_nested_fields_should_automatic_bind_mapping()
671+
public void Read_csv_file_with_autobind_should_support_nested_fields()
671672
{
672673
// Arrange
673674

@@ -700,15 +701,15 @@ public void Read_csv_file_with_header_containing_nested_fields_should_automatic_
700701

701702
// Act
702703

703-
var items = reader.ReadRecords<Person>(readOptions, skipMismatchedColumns: false);
704+
var items = reader.ReadRecords<Person>(readOptions, skipUnmatchedColumns: false);
704705

705706
// Assert
706707

707708
items.Should().BeEquivalentTo(expected, cfg => cfg.WithStrictOrdering());
708709
}
709710

710711
[Fact]
711-
public void Read_csv_file_with_header_containing_inherited_fields_should_automatic_bind_mapping()
712+
public void Read_csv_file_with_autobind_should_support_inherited_properties()
712713
{
713714
// Arrange
714715

@@ -744,7 +745,7 @@ public void Read_csv_file_with_header_containing_inherited_fields_should_automat
744745

745746
// Act
746747

747-
var items = reader.ReadRecords<PersonDerivated>(readOptions, skipMismatchedColumns: true);
748+
var items = reader.ReadRecords<PersonDerivated>(readOptions, skipUnmatchedColumns: true);
748749

749750
// Assert
750751

@@ -755,7 +756,7 @@ public void Read_csv_file_with_header_containing_inherited_fields_should_automat
755756
[InlineData(" ", false)]
756757
[InlineData(" ", true)]
757758
[InlineData("BirthDay ; Name ; Mother.BirthDay; Mother.Name", false)]
758-
public void Read_csv_file_without_header_should_throw_when_automatic_bind_mapping(string header, bool hasHeader)
759+
public void Read_csv_file_with_autobind_should_throw_when_missing_header(string header, bool hasHeader)
759760
{
760761
// Arrange
761762

@@ -788,7 +789,7 @@ public void Read_csv_file_without_header_should_throw_when_automatic_bind_mappin
788789

789790
// Act
790791

791-
var action = () => reader.ReadRecords<Person>(readOptions, skipMismatchedColumns: true);
792+
var action = () => reader.ReadRecords<Person>(readOptions, skipUnmatchedColumns: true);
792793

793794
// Assert
794795

RecordParser/Extensions/FileReader/FixedLengthReaderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class FixedLengthReaderOptions<T>
1313
/// </summary>
1414
public ParallelismOptions ParallelismOptions { get; set; }
1515
/// <summary>
16-
/// Function which parses text into object
16+
/// Function which parses text to object
1717
/// </summary>
1818
public FuncSpanT<T> Parser { get; set; }
1919
}
@@ -24,7 +24,7 @@ public static class FixedLengthReaderExtensions
2424

2525
/// <summary>
2626
/// Reads the records (i.e., lines) from a fixed length file,
27-
/// then parses the records into objects.
27+
/// then parses the records to objects.
2828
/// </summary>
2929
/// <typeparam name="T">type of objects read from file</typeparam>
3030
/// <param name="reader">fixed length file</param>

RecordParser/Extensions/FileReader/VariableLengthReaderExtensions.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static class VariableLengthReaderExtensions
3535
{
3636
/// <summary>
3737
/// Reads the records from a variable length file,
38-
/// then parses the records into objects.
38+
/// then parses the records to objects.
3939
/// </summary>
4040
/// <typeparam name="T">type of objects read from file</typeparam>
4141
/// <param name="reader">variable length file</param>
@@ -58,10 +58,29 @@ public static IEnumerable<T> ReadRecords<T>(this TextReader reader, IVariableLen
5858
: ReadRecordsSequential(selector, func, options.HasHeader);
5959
}
6060

61+
/// <summary>
62+
/// Reads the records from a variable length file
63+
/// using the header of the file to auto-bind columns to properties in the process of parsing the records to objects.
64+
/// </summary>
65+
/// <typeparam name="T">type of objects read from file</typeparam>
66+
/// <param name="reader">variable length file</param>
67+
/// <param name="options">options to configure the parsing</param>
68+
/// <param name="skipUnmatchedColumns">
69+
/// If true then header columns without a matching property or field will simply be ignored;
70+
/// otherwise, an exception will be thrown indicating the non-matching column.
71+
/// Default value is true.
72+
/// </param>
73+
/// <param name="action">callback to set additional bind or default type converters</param>
74+
/// <returns>
75+
/// Sequence of records.
76+
/// </returns>
77+
/// <exception cref="InvalidOperationException">
78+
/// If the header is missing on <paramref name="reader"/> or <paramref name="options"/> indicating that header is absent.
79+
/// </exception>
6180
public static IEnumerable<T> ReadRecords<T>(this
6281
TextReader reader,
6382
VariableLengthReaderOptions options,
64-
bool skipMismatchedColumns = false,
83+
bool skipUnmatchedColumns = true,
6584
Action<IVariableLengthReaderSequentialBuilder<T>> action = null)
6685
{
6786
string header;
@@ -71,7 +90,7 @@ public static IEnumerable<T> ReadRecords<T>(this
7190

7291
var separator = DetectDelimiter(header.AsMemory());
7392
var columns = header.Split(separator);
74-
var parser = BuildParser(columns, separator, skipMismatchedColumns, action);
93+
var parser = BuildParser(columns, separator, skipUnmatchedColumns, action);
7594

7695
return ReadRecords(reader, parser, options with { HasHeader = false });
7796
}

0 commit comments

Comments
 (0)