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
This is the solution I made:
public class CalendarExceptionEnumConverter : DefaultTypeConverter where T : struct
{
public override string ConvertToString(TypeConverterOptions options, object value)
{
T result;
if(Enum.TryParse(value.ToString(),out result))
{
return (Convert.ToInt32(result)).ToString();
}
throw new InvalidCastException(String.Format("Invalid value to EnumConverter. Type: {0} Value: {1}",typeof(T),value));
}
}
and used it as the following:
Map(m => m.ExceptionEntityType).TypeConverter>();