title: How to use EnumConverter with CsvHelper
body: <p>I'm using <a href="http://joshclose.github.io/CsvHelper/" rel="nofollow">CsvHelper</a> to serialize a class to csv file - until here everything works well.</p>
  
  <p>Now I'm trying to find a way to convert the class's enum properties to their int value in the csv, so I could use the CSV for bulk insert later.</p>
  
  <p>I found out the EnumConverter class in CsvHelper but I can't figure out how to properly use it, as all my tries are failing.</p>
  
  <p>Here is my mapping class code</p>
  
  <pre><code> public sealed class MyMapping : CsvClassMap&lt;TradingCalendarException&gt;
      {
          public MyMapping()
          {
              EnumConverter enumConverter = new EnumConverter(typeof(CalendarExceptionEntityType));
  
              Map(m =&gt; m.ExceptionEntityType).Index(0).Name("EXCEPTION_ENTITY_TYPE").TypeConverter(enumConverter);
              Map(m =&gt; m.ExceptionEntityIdentifier).Index(1).Name("EXCEPTION_ENTITY_IDENTIFIER");
              Map(m =&gt; m.OptionType).Index(2).Name("OPTION_TYPE");
              Map(m =&gt; m.StartDatetime).Index(3).Name("EXCEPTION_START_DATETIME");
              Map(m =&gt; m.EndDatetime).Index(4).Name("EXCEPTION_END_DATETIME");
              Map(m =&gt; m.DataSourceType).Index(5).Name("DATA_SOURCE_TYPE");
              Map(m =&gt; m.Description).Index(6).Name("DESCRIPTION");
          }
      }
  </code></pre>
  
  <p>and the writing part</p>
  
  <pre><code>using (StreamWriter file = new StreamWriter(filePath, false, Encoding.UTF8))
          {
              CsvWriter writer = new CsvWriter(file);
              MyMapping mapping = new MyMapping();
              writer.Configuration.RegisterClassMap(mapping);
  
              writer.WriteRecords(calendarExceptionList);
          }
  </code></pre>
  
  <p><strong>The rest of the mapping (indexing and naming) is working</strong>, it's just the EnumConverter that doesn't do any change.</p>
  
  <p>I didn't find any examples online.</p>
  
  <p>Thank you!</p>