public sealed class CsvTable<T> : CsvQuery<T>
Namespace
CsvHelper.Linq
Assembly
CsvHelper.Linq.dll
Inheritance
object CsvQuery<T> CsvTable<T>
Builds
net10.0 netstandard2.1 netstandard2.0 net47

Properties

Path

Added in v34.0.0
public string Path { get; }

The path of the file.

Property value

string

View source

Methods

public long AppendRecords(IEnumerable<T> records)

Adds records to the end of the file, creating it (with a header) when it does not exist or is empty. They are written with the file's separator and line break, after a line break when the file does not end with one.

Parameters

recordsIEnumerable<T>
The records, enumerated once.

Returns

long
The number of records added.

Exceptions

ArgumentNullException
records is null.
InvalidOperationException
The file's header is not the one that the records are written with.

View source

public ValueTask<long> AppendRecordsAsync(IAsyncEnumerable<T> records, CancellationToken cancellationToken = default)

Adds an asynchronous sequence of records to the end of the file asynchronously; see AppendRecords.

Parameters

recordsIAsyncEnumerable<T>
The records, enumerated once.
cancellationTokenCancellationToken
Cancels reading the records and writing.

Returns

ValueTask<long>
The number of records added.

Exceptions

ArgumentNullException
records is null.
InvalidOperationException
The file's header is not the one that the records are written with.

View source

public ValueTask<long> AppendRecordsAsync(IEnumerable<T> records, CancellationToken cancellationToken = default)

Adds records to the end of the file asynchronously; see AppendRecords.

Parameters

recordsIEnumerable<T>
The records, enumerated once.
cancellationTokenCancellationToken
Cancels writing.

Returns

ValueTask<long>
The number of records added.

Exceptions

ArgumentNullException
records is null.
InvalidOperationException
The file's header is not the one that the records are written with.

View source

public long Delete(Expression<Func<T, bool>> predicate)

Removes the records that match a condition from the file, with their line breaks. Everything else is kept byte for byte. The condition reads only the members it uses; a record that cannot be read, and that CsvReaderOptions.OnRecordError skips, is kept. The file is rewritten next to itself and replaced when the new one is complete, so a failure leaves it as it was.

Parameters

predicateExpression<Func<T, bool>>
The condition of the records to remove.

Returns

long
The number of records removed.

Exceptions

ArgumentNullException
predicate is null.
NotSupportedException
The file is not UTF-8.

View source

public ValueTask<long> DeleteAsync(Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)

Removes the records that match a condition from the file, asynchronously; see Delete.

Parameters

predicateExpression<Func<T, bool>>
The condition of the records to remove.
cancellationTokenCancellationToken
Cancels the rewrite, which leaves the file as it was.

Returns

ValueTask<long>
The number of records removed.

Exceptions

ArgumentNullException
predicate is null.
NotSupportedException
The file is not UTF-8.

View source

public long Update(Expression<Func<T, bool>> predicate, Func<T, T> update)

Changes the records that match a condition: each is replaced by what update makes of it, in which only the fields whose values changed are written again; the others, the columns that T does not map, and the rest of the file are kept byte for byte. The file is rewritten next to itself and replaced when the new one is complete, so a failure leaves it as it was.

Parameters

predicateExpression<Func<T, bool>>
The condition of the records to change.
updateFunc<T, T>
Makes the new record of a record, such as o => o with { Status = "Open" }; it may also change the record it gets and return it.

Returns

long
The number of records changed.

Exceptions

ArgumentNullException
predicate or update is null.
InvalidOperationException
The update changes a member that the file has no column for.
NotSupportedException
The file is not UTF-8, is fixed-width, or quotes with another character than ".

View source

public ValueTask<long> UpdateAsync(Expression<Func<T, bool>> predicate, Func<T, T> update, CancellationToken cancellationToken = default)

Changes the records that match a condition, asynchronously; see Update.

Parameters

predicateExpression<Func<T, bool>>
The condition of the records to change.
updateFunc<T, T>
Makes the new record of a record; it may also change the record it gets and return it.
cancellationTokenCancellationToken
Cancels the rewrite, which leaves the file as it was.

Returns

ValueTask<long>
The number of records changed.

Exceptions

ArgumentNullException
predicate or update is null.
InvalidOperationException
The update changes a member that the file has no column for.
NotSupportedException
The file is not UTF-8, is fixed-width, or quotes with another character than ".

View source