Configuration used for reading and writing CSV data.
- Namespace
- CsvHelper
.Configuration - Interfaces
- Base Types
-
- object
graph BT
Type-->Base0["object"]
Type-.->Interface0["IReaderConfiguration"]
click Interface0 "/CsvHelper/api/CsvHelper.Configuration/IReaderConfiguration"
Type-.->Interface1["IParserConfiguration"]
click Interface1 "/CsvHelper/api/CsvHelper.Configuration/IParserConfiguration"
Type-.->Interface2["IWriterConfiguration"]
click Interface2 "/CsvHelper/api/CsvHelper.Configuration/IWriterConfiguration"
Type-.->Interface3["IEquatable<CsvConfiguration>"]
Type["CsvConfiguration"]
class Type type-node
Syntax
public record CsvConfiguration : IReaderConfiguration, IParserConfiguration, IWriterConfiguration,
IEquatable<CsvConfiguration>
Constructors
Name | Summary |
---|---|
CsvConfiguration |
Initializes a new instance of the CsvConfiguration class
using the given System.Globalization.CultureInfo . Since Delimiter
uses CultureInfo for its default, the given System.Globalization.CultureInfo
will be used instead.
|
CsvConfiguration |
Initializes a new instance of the CsvConfiguration class
using the given CultureInfo . Since Delimiter
uses CultureInfo for its default, the given CultureInfo
will be used instead.
|
Properties
Name | Property Type | Summary |
---|---|---|
AllowComments | bool |
Gets a value indicating if comments are allowed.
true to allow commented out lines, otherwise false .
|
BadDataFound | BadDataFound |
Gets the function that is called when bad field data is found. A field
has bad data if it contains a quote and the field is not quoted (escaped).
You can supply your own function to do other things like logging the issue
instead of throwing an exception.
|
BufferSize | int |
Gets the size of the buffer
used for parsing and writing CSV files.
Default is 0x1000.
|
CacheFields | bool |
Cache fields that are created when parsing.
Default is false.
|
Comment | char |
Gets the character used to denote
a line that is commented out. Default is '#'.
|
CountBytes | bool |
Gets a value indicating whether the number of bytes should
be counted while parsing. Default is false. This will slow down parsing
because it needs to get the byte count of every char for the given encoding.
The
Encoding needs to be set correctly for this to be accurate.
|
CultureInfo | CultureInfo |
Gets the culture info used to read an write CSV files.
|
Delimiter | string |
The delimiter used to separate fields.
Default is
System.Globalization.TextInfo.ListSeparator .
|
Detect |
bool |
Gets a value indicating whether changes in the column
count should be detected. If true, a
BadDataException
will be thrown if a different column count is detected.
|
DetectDelimiter | bool |
Detect the delimiter instead of using the delimiter from configuration.
Default is
false .
|
Detect |
string[] |
The possible delimiter values used when detecting the delimiter.
Default is [",", ";", "|", "\t"].
|
DynamicPropertySort | IComparer |
Gets the comparer used to order the properties
of dynamic objects when writing. The default is null,
which will preserve the order the object properties
were created with.
|
Encoding | Encoding |
Gets the encoding used when counting bytes.
|
Escape | char |
The character used to escape characters.
Default is '"'.
|
Exception |
bool |
A value indicating if exception messages contain raw CSV data.
true if exception contain raw CSV data, otherwise false .
Default is true .
|
GetConstructor | GetConstructor |
Chooses the constructor to use for constructor mapping.
|
GetDelimiter | GetDelimiter |
Gets the function that is called when
DetectDelimiter is enabled.
|
Get |
Get |
Gets the name to use for the property of the dynamic object.
|
HasHeaderRecord | bool |
Gets a value indicating if the
CSV file has a header record.
Default is true.
|
HeaderValidated | HeaderValidated |
Gets the function that is called when a header validation check is ran. The default function
will throw a
ValidationException if there is no header for a given member mapping.
You can supply your own function to do other things like logging the issue instead of throwing an exception.
|
IgnoreBlankLines | bool |
Gets a value indicating if blank lines
should be ignored when reading.
true to ignore, otherwise false . Default is true.
|
IgnoreReferences | bool |
Gets a value indicating whether references
should be ignored when auto mapping.
true to ignore
references, otherwise false . Default is false.
|
Include |
bool |
Gets a value indicating if private
member should be read from and written to.
true to include private member, otherwise false . Default is false.
|
InjectionCharacters | char[] |
Gets the characters that are used for injection attacks.
|
Injection |
char |
Gets the character used to escape a detected injection.
|
InjectionOptions | InjectionOptions |
Gets the injection options.
|
IsNewLineSet | bool |
A value indicating if
NewLine was set.
|
Line |
bool |
Gets a value indicating if a line break found in a quote field should
be considered bad data.
true to consider a line break bad data, otherwise false .
Defaults to false.
|
MaxFieldSize | double |
Gets or sets the maximum size of a field.
Defaults to 0, indicating maximum field size is not checked.
|
MemberTypes | MemberTypes |
Gets the member types that are used when auto mapping.
MemberTypes are flags, so you can choose more than one.
Default is Properties.
|
MissingFieldFound | MissingFieldFound |
Gets the function that is called when a missing field is found. The default function will
throw a
MissingFieldException . You can supply your own function to do other things
like logging the issue instead of throwing an exception.
|
Mode | CsvMode |
The mode.
See
CsvMode for more details.
|
NewLine | string |
The newline string to use. Default is \r\n (CRLF).
When writing, this value is always used.
When reading, this value is only used if explicitly set.
If not set, the parser uses one of \r\n, \r, or \n.
|
Prepare |
Prepare |
Prepares the header field for matching against a member name.
The header field and the member name are both ran through this function.
You should do things like trimming, removing whitespace, removing underscores,
and making casing changes to ignore case.
|
Process |
int |
The size of the buffer used when processing fields.
Default is 1024.
|
Quote | char |
Gets the character used to quote fields.
Default is '"'.
|
Reading |
Reading |
Gets the function that is called when a reading exception occurs.
The default function will re-throw the given exception. If you want to ignore
reading exceptions, you can supply your own function to do other things like
logging the issue.
|
Reference |
Reference |
Gets a callback that will return the prefix for a reference header.
|
ShouldQuote | ShouldQuote |
Gets a function that is used to determine if a field should get quoted
when writing.
|
ShouldSkipRecord | ShouldSkipRecord |
Gets the callback that will be called to
determine whether to skip the given record or not.
|
Should |
Should |
Determines if constructor parameters should be used to create
the class instead of the default constructor and members.
|
TrimOptions | TrimOptions |
Gets the field trimming options.
|
Use |
bool |
Gets a value indicating that during writing if a new
object should be created when a reference member is null.
True to create a new object and use it's defaults for the
fields, or false to leave the fields empty for all the
reference member's member.
|
WhiteSpaceChars | char[] |
Characters considered whitespace.
Used when trimming fields.
Default is [' '].
|
Methods
Name | Return Value | Summary |
---|---|---|
ApplyAttributes |
CsvConfiguration |
Applies class level attribute to configuration.
|
ApplyAttributes |
CsvConfiguration |
Applies class level attribute to configuration.
|
FromAttributes |
CsvConfiguration |
Creates a
CsvConfiguration instance configured using cultureInfo
and CsvHelper attributes applied to type at the type-level.
This method ignores any CultureInfoAttribute applied to type.
static
|
FromAttributes |
CsvConfiguration |
Creates a
CsvConfiguration instance configured using CsvHelper attributes applied
to type at the type-level. This method requires type to
be annotated with CultureInfoAttribute (or to sub-class a type which is).
static
|
FromAttributes |
CsvConfiguration |
Creates a
CsvConfiguration instance configured using CsvHelper attributes applied
to T at the type-level. This method requires T to
be annotated with CultureInfoAttribute (or to sub-class a type which is).
static
|
FromAttributes |
CsvConfiguration |
Creates a
CsvConfiguration instance configured using cultureInfo
and CsvHelper attributes applied to T at the type-level.
This method ignores any CultureInfoAttribute applied to T.
static
|
Validate |
void |
Validates the configuration.
|
Operators
Name | Value | Summary |
---|---|---|
operator != |
bool | |
operator == |
bool |