Parse<TEnum>(CsvField)
Parses the value of the field as the enum TEnum.
Type parameters
TEnum- The enum type.
Parameters
fieldCsvField- The field.
Returns
TEnum.Exceptions
- FormatException
- The value is not a value of
TEnum.
Static class in CsvHelper
The overloads of Parse<T>, TryParse<T> and ParseOrNull<T> for enums, whose types are not ISpanParsable<T>: reader.Parse<Status>(2) calls the method of this class. An enum field is read as the generated mappers of CsvRecordAttribute types read enum members: the names of the members and their CsvEnumNameAttribute names, ignoring ASCII case unless two names of different members differ only in case, then numbers and lists of flags (Read, Write) as Enum.TryParse reads them, ignoring case.
public static class CsvEnumExtensionsCsvHelperCsvHelper.dllOn .NET Framework and .NET Standard, where Parse<T> has no constraint, the methods of the reader, its rows and fields, and dynamic records parse enums themselves, the same way, and this class does not exist.
Parses the value of the field as the enum TEnum.
TEnumfieldCsvFieldTEnum.TEnum.public static TEnum Parse<TEnum>(this CsvDynamicRecord record, string name) where TEnum : struct, EnumParses the field of the column called name as the enum TEnum.
TEnumrecordCsvDynamicRecordnamestringTEnum.record or name is null.TEnum.Parses field index as the enum TEnum.
TEnumreaderCsvReaderindexintTEnum.reader is null.TEnum.index is negative.index is not less than CsvReader.FieldCount and CsvReaderOptions.MissingField is CsvMissingFieldHandling.Throw.Parses the field with the given header name as the enum TEnum.
TEnumreaderCsvReadernamestringTEnum.reader or name is null.TEnum.Parses field index of the row as the enum TEnum.
TEnumrowCsvRowindexintTEnum.TEnum.index is negative.index is not less than CsvRow.FieldCount and CsvReaderOptions.MissingField is CsvMissingFieldHandling.Throw.Parses the value of the field as the enum TEnum, or returns null if it is empty, one of CsvReaderOptions.NullValues or not a value of TEnum.
TEnumfieldCsvFieldnull when the value is null or not a value of TEnum.Tries to parse the value of the field as the enum TEnum.
TEnumfieldCsvFieldvalueTEnumTEnum when the value is not a value of it.public static bool TryParse<TEnum>(this CsvReader reader, int index, out TEnum value) where TEnum : struct, EnumTries to parse field index as the enum TEnum.
TEnumreaderCsvReaderindexintvalueTEnumTEnum when the field is not a value of it.reader is null.index is negative.index is not less than CsvReader.FieldCount and CsvReaderOptions.MissingField is CsvMissingFieldHandling.Throw.