CsvValidateAttribute(string)
public CsvValidateAttribute(string methodName)Checks the member's value with the static method called methodName.
Parameters
methodNamestring- The name of the method, such as
nameof(IsValidAge).
Attribute in CsvHelper
Checks the value of a member of a CsvRecordAttribute type with a static method of the type, such as [CsvValidate(nameof(IsValidAge))]: a value that the method rejects makes the record fail with a CsvValidationException, which the record methods of CsvReader report in a CsvFormatException that names the record, the field and the member.
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
public sealed class CsvValidateAttribute : AttributeCsvHelperCsvHelper.dllThe method is a static method of the type (of the map class, for a CsvRecordMapAttribute), of any accessibility, that takes one parameter of the member's type and returns bool: true for a valid value. It runs after the field is read, so it sees the value as the member gets it (null for an empty field of a nullable member, the value of CsvDefaultAttribute). It does not run when the column of an optional member is missing, nor when records are written.
public CsvValidateAttribute(string methodName)Checks the member's value with the static method called methodName.
methodNamestringnameof(IsValidAge).public string? Message { get; set; }The message of the CsvValidationException, such as "Age must be between 0 and 150.", or null (the default) for one that names the member and, when CsvReaderOptions.IncludeValuesInExceptions is on, the value.
public string MethodName { get; }The name of the method that checks the value.