CsvConverterOpenReadTResult(TextReader, CsvMapping, FuncObject, TResult, Char, Boolean, CsvOpts) Method

Initializes a CsvReaderTResult instance to parse CSV data as a collection of TResult instances.

Definition

Namespace: FolkerKinzel.CsvTools.Mappings
Assembly: FolkerKinzel.CsvTools.Mappings (in FolkerKinzel.CsvTools.Mappings.dll) Version: 1.1.0+1263e8243dc2cd78095f678f813d7d9c52ea4315
C#
public static CsvReader<TResult> OpenRead<TResult>(
	TextReader reader,
	CsvMapping mapping,
	Func<Object, TResult> conversion,
	char delimiter = ',',
	bool isHeaderPresent = true,
	CsvOpts options = CsvOpts.Default
)

Parameters

reader  TextReader
The TextReader with which the CSV data is read.
mapping  CsvMapping
The CsvMapping used to convert the CSV data.
conversion  FuncObject, TResult

A function that converts the content of mapping to an instance of TResult.

The function is called for each row in the CSV data and gets the CsvMapping as argument, filled with the current CsvRecord instance. The CsvMapping is passed to the function as dynamic argument: Inside the function the registered DynamicProperty instances can be used like regular .NET properties, but without IntelliSense ("late binding").

delimiter  Char  (Optional)
The field separator character.
isHeaderPresent  Boolean  (Optional)
true, to interpret the first line as a header, otherwise false.
options  CsvOpts  (Optional)
Options for reading CSV.

Type Parameters

TResult
Generic type parameter that specifies the Type of the items that the CsvReaderTResult returns.

Return Value

CsvReaderTResult
A CsvReaderTResult that allows you to iterate through the data parsed from the CSV.

Remarks

When importing CSV data from Excel, the appropriate arguments can be determined with GetExcelArguments.

Exceptions

ArgumentNullExceptionreader, or mapping, or conversion is null.
ArgumentOutOfRangeExceptiondelimiter is either the double quotes " or a line break character ('\r' or '\n').

See Also