How to use EnumConverter with CsvHelper

后端 未结 4 1365
执念已碎
执念已碎 2020-12-10 18:08

I\'m using CsvHelper to serialize a class to csv file - until here everything works well.

Now I\'m trying to find a way to convert the class\'s enum properties to th

4条回答
  •  被撕碎了的回忆
    2020-12-10 19:09

    Add a int property to your TradingCalendarException class that casts back and forth to your custom enum, CalendarExceptionEntityType, like:

    public int ExceptionEntityTypeInt { 
        get { return (int)ExceptionEntityType; } 
        set { ExceptionEntityType = (CalendarExceptionEntityType)value; } 
    }
    

    Use Map(m => m.ExceptionEntityTypeInt).Index(0).Name("EXCEPTION_ENTITY_TYPE_INT") instead of your enum converter Map(m => m.ExceptionEntityType).Index(0).Name("EXCEPTION_ENTITY_TYPE").TypeConverter(new MyMapping())

提交回复
热议问题