mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-30 23:24:00 +08:00
32 lines
864 B
C#
32 lines
864 B
C#
using CsvHelper;
|
|
using CsvHelper.Configuration;
|
|
using CsvHelper.TypeConversion;
|
|
|
|
namespace ThingsGateway.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();
|
|
}
|
|
}
|
|
}
|