CsvConverterOpenReadAnalyzedTResult(String, CsvToTResult, Encoding, Header, Int32) Method

Opens a CSV file for parsing its data after it had been analyzed.

Definition

Namespace: FolkerKinzel.CsvTools.Mappings
Assembly: FolkerKinzel.CsvTools.Mappings (in FolkerKinzel.CsvTools.Mappings.dll) Version: 1.1.0+1263e8243dc2cd78095f678f813d7d9c52ea4315
C#
public static CsvReader<TResult> OpenReadAnalyzed<TResult>(
	string filePath,
	CsvTo<TResult> converter,
	Encoding? defaultEncoding = null,
	Header header = Header.ProbablyPresent,
	int analyzedLines = 5
)

Parameters

filePath  String
File path of the CSV file to read.
converter  CsvToTResult
An object that converts a CSV row to a TResult instance.
defaultEncoding  Encoding  (Optional)
The text Encoding to be used if the CSV file has no byte order mark (BOM), or null to use UTF8 in this case. Use GetExcelArguments to get the appropriate argument for this parameter when importing CSV data from Excel.
header  Header  (Optional)
A supposition that is made about the presence of a header row.
analyzedLines  Int32  (Optional)
Maximum number of lines to analyze in the CSV file. The minimum value is AnalyzedLinesMinCount. If the file has fewer lines than analyzedLines, it will be analyzed completely. (You can specify Int32.MaxValue to analyze the entire file in any case.)

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 file.

Remarks

The method performs a statistical analysis on the CSV file. The result of the analysis is therefore always only an estimate, the accuracy of which increases with the number of lines analyzed.

The field delimiters COMMA (',', %x2C), SEMICOLON (';', %x3B), HASH ('#', %x23), TAB ('\t', %x09), and SPACE (' ', %x20) are recognized automatically.

This method also tries to determine the Encoding of the CSV file from the byte order mark (BOM). If no byte order mark can be found, defaultEncoding is used.

Exceptions

ArgumentNullExceptionfilePath, or converter is null.
ArgumentOutOfRangeException

header is not a defined value of the Header enum.

- or -

header is a combination of Header values.

CsvFormatExceptionInvalid CSV file. Try to increase the value of analyzedLines to get a better analyzer result!

See Also