Search code examples
c#csvhelper

Passing an instance to a class used with registerclassmap


I use registerclassmap to map values with CSVReader, like below:

AppSettings settings;
...
csvReader.Configuration.RegisterClassMap<EmployeeMapping>();

How to pass the settings instance to use it in the EmployeeMappaing instance created by CSVReader?


Solution

  • Are you looking to do something like this? You can create the EmployeeMapping instance yourself rather than have RegisterClassMap create the instance.

    AppSettings settings;
    ...
    csvReader.Configuration.RegisterClassMap(new EmployeeMapping(settings));