using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Reflection;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace WIDESEAWCS_Common.Helper
|
{
|
public static class AttributeHelper
|
{
|
/// <summary>
|
/// 获取属性的 ExporterHeader 显示名称
|
/// </summary>
|
public static string GetExporterDisplayName(PropertyInfo property)
|
{
|
try
|
{
|
// 获取 ExporterHeaderAttribute 特性
|
var exporterHeaderAttr = property.GetCustomAttributes()
|
.FirstOrDefault(attr => attr.GetType().Name == "ExporterHeaderAttribute");
|
|
if (exporterHeaderAttr != null)
|
{
|
// 使用反射获取 DisplayName 属性
|
var displayNameProp = exporterHeaderAttr.GetType().GetProperty("DisplayName");
|
if (displayNameProp != null)
|
{
|
var displayName = displayNameProp.GetValue(exporterHeaderAttr) as string;
|
if (!string.IsNullOrEmpty(displayName))
|
{
|
return displayName;
|
}
|
}
|
|
// 检查是否被忽略
|
var isIgnoreProp = exporterHeaderAttr.GetType().GetProperty("IsIgnore");
|
if (isIgnoreProp != null)
|
{
|
var isIgnore = (bool)isIgnoreProp.GetValue(exporterHeaderAttr);
|
if (isIgnore)
|
{
|
return null; // 返回 null 表示忽略此列
|
}
|
}
|
}
|
}
|
catch
|
{
|
// 如果出错,返回属性名
|
}
|
|
return property.Name; // 默认返回属性名
|
}
|
}
|
}
|