mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-04 20:57:58 +08:00
35 lines
919 B
C#
35 lines
919 B
C#
using CsvHelper.Configuration;
|
|
using CsvHelper.TypeConversion;
|
|
using CsvHelper;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace SqlSugar
|
|
{
|
|
public class CsvHelperEnumToIntConverter : ITypeConverter
|
|
{
|
|
public string ConvertToString(object value, IWriterRow row, MemberMapData memberMapData)
|
|
{
|
|
if (value == null)
|
|
{
|
|
return "null";
|
|
}
|
|
else if (value is Enum enumValue)
|
|
{
|
|
return (Convert.ToInt32(enumValue)).ToString();
|
|
}
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public object ConvertFromString(string text, IReaderRow row, MemberMapData memberMapData)
|
|
{
|
|
if (int.TryParse(text, out int intValue))
|
|
{
|
|
return text;
|
|
}
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
}
|