Custom conversions when writing CSV files using CsvHelper

前端 未结 1 1687
梦如初夏
梦如初夏 2020-12-16 22:24

I\'ve been doing some CSV reading and writing lately, and ran across CsvHelper which is fantastic so far. I\'ve ran into one small problem; I use a custom converter when re

相关标签:
1条回答
  • 2020-12-16 23:00

    You can do it with a custom type converters (https://github.com/JoshClose/CsvHelper/wiki/Custom-TypeConverter). Just override ConvertToString method.

    public class TestConverter : DefaultTypeConverter
    {
        public override string ConvertToString(TypeConverterOptions options, object value)
        {
            return base.ConvertToString(options, value);
        }
    }
    

    and specify converter when mapping:

    Map(m => m.PersonId).Index(0).TypeConverter<TestConverter>();
    
    0 讨论(0)
提交回复
热议问题