CsvConverterExtensionToCsvTSource(IEnumerableTSource, Int32, CsvMapping, ActionTSource, Object, Char) Method

Converts a collection of TSource instances to a CSV String without a header row.

Definition

Namespace: FolkerKinzel.CsvTools.Mappings
Assembly: FolkerKinzel.CsvTools.Mappings (in FolkerKinzel.CsvTools.Mappings.dll) Version: 1.1.0+1263e8243dc2cd78095f678f813d7d9c52ea4315
C#
public static string ToCsv<TSource>(
	this IEnumerable<TSource> data,
	int columnsCount,
	CsvMapping mapping,
	Action<TSource, Object> conversion,
	char delimiter = ','
)

Parameters

data  IEnumerableTSource
The data to convert to CSV. Each item will be represented with a CSV row.
columnsCount  Int32
Number of columns in the CSV file.
mapping  CsvMapping
The CsvMapping used to convert a TSource instance to a CSV row.
conversion  ActionTSource, Object

A method that fills the content of a TSource instance into the properties of mapping.

conversion is called with each CSV row to be written and it gets the TSource instance and mapping as arguments. mapping is passed to the method as dynamic argument: Inside the conversion method the registered DynamicProperty instances can be used like regular .NET properties, but without IntelliSense ("late binding").

With each call of conversion all DynamicProperty instances in mapping are reset to their DefaultValue.

delimiter  Char  (Optional)
The field separator character.

Type Parameters

TSource
Generic type parameter for the data type to write as CSV row.

Return Value

String
A CSV String without header row that contains the contents of data.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTSource. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Exceptions

ArgumentNullExceptiondata, or mapping, or conversion is null.
IOExceptionI/O error.

See Also