| | |
| | | /// </summary> |
| | | public static class ExportHelper |
| | | { |
| | | |
| | | |
| | | // 批量转换方法 |
| | | public static List<Dictionary<string, object>> ConvertListToExportData<T>(IEnumerable<T> list) |
| | | { |
| | | return list.Select(ConvertToExportData).ToList(); |
| | | } |
| | | |
| | | // 通用转换方法(兼容 Func<T, Dictionary<string, object>>) |
| | | public static Dictionary<string, object> ConvertToExportData<T>(T entity) |
| | | { |
| | |
| | | dict[prop.Name] = FormatValue(value); |
| | | } |
| | | return dict; |
| | | } |
| | | |
| | | // 批量转换方法 |
| | | public static List<Dictionary<string, object>> ConvertListToExportData<T>(IEnumerable<T> list) |
| | | { |
| | | return list.Select(ConvertToExportData).ToList(); |
| | | } |
| | | |
| | | private static object FormatValue(object value) |
| | |
| | | return value; |
| | | } |
| | | |
| | | private static string GetEnumDescription(Enum value) |
| | | { |
| | | var fieldInfo = value.GetType().GetField(value.ToString()); |
| | | var description = fieldInfo? |
| | | .GetCustomAttributes(typeof(DescriptionAttribute), false) |
| | | .FirstOrDefault() as DescriptionAttribute; |
| | | return description?.Description ?? value.ToString(); |
| | | } |
| | | } |
| | | } |