using System; using System.Collections.Generic; using System.Collections.Generic; using System.ComponentModel; using System.Reflection; using System.Threading.Tasks; namespace CMS.Plugin.HIAWms.Domain.Shared.Util { /// /// 导出帮助类. /// public static class ExportHelper { // 批量转换方法 public static List> ConvertListToExportData(IEnumerable list) { return list.Select(ConvertToExportData).ToList(); } // 通用转换方法(兼容 Func>) public static Dictionary ConvertToExportData(T entity) { var dict = new Dictionary(); if (entity == null) return dict; foreach (var prop in typeof(T).GetProperties()) { var value = prop.GetValue(entity); dict[prop.Name] = FormatValue(value); } return dict; } private static object FormatValue(object value) { if (value == null) return string.Empty; // 处理枚举 if (value is Enum enumValue) return GetEnumDescriptionUtil.GetEnumDescription(enumValue); // 处理布尔 if (value is bool boolValue) return boolValue ? "是" : "否"; return value; } } }