CsvConverterParseAnalyzedTResult(String, CsvMapping, FuncObject, TResult, Header, Int32) Method

Parses a CSV-String 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 TResult[] ParseAnalyzed<TResult>(
	string csv,
	CsvMapping mapping,
	Func<Object, TResult> conversion,
	Header header = Header.ProbablyPresent,
	int analyzedLines = 5
)

Parameters

csv  String
The CSV-String to parse.
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 csv 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").

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 csv. The minimum value is AnalyzedLinesMinCount. If csv has fewer lines than analyzedLines, it will be analyzed completely. (You can specify Int32.MaxValue to analyze the entire String in any case.)

Type Parameters

TResult
Generic type parameter that specifies the Type of the items in the array that the method returns.

Return Value

TResult
An array of TResult instances, initialized from the parsed csv.

Remarks

CsvAnalyzer performs a statistical analysis on csv. 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.

Exceptions

ArgumentNullExceptioncsv, or mapping, or conversion 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!
FormatException Parsing fails and Throwing is true.

See Also