wangxinhui
2026-03-26 ad05ef2341fe19a4220f7ada1987636f9ec4a1a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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; // 默认返回属性名
        }
    }
}