|
|
|
@ -1,4 +1,6 @@ |
|
|
|
|
using System.Text; |
|
|
|
|
using System.ComponentModel; |
|
|
|
|
using System.Reflection; |
|
|
|
|
using System.Text; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Common.Helper; |
|
|
|
|
|
|
|
|
@ -232,4 +234,59 @@ public class StringHelper |
|
|
|
|
catch (Exception) { throw; } |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region 获取字段描述 |
|
|
|
|
/// <summary> |
|
|
|
|
/// 对象字段描述 |
|
|
|
|
/// </summary> |
|
|
|
|
private static Dictionary<string, Dictionary<string, string>> m_FieldDesc = new Dictionary<string, Dictionary<string, string>>(); |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 获取字段的描述(描述 - 列名) |
|
|
|
|
/// </summary> |
|
|
|
|
/// <typeparam name="T"></typeparam> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public static Dictionary<string, string> GetFieldDesc<T>() |
|
|
|
|
{ |
|
|
|
|
var type = typeof(T).ToString(); |
|
|
|
|
lock (m_FieldDesc) |
|
|
|
|
{ |
|
|
|
|
if (m_FieldDesc.ContainsKey(type)) |
|
|
|
|
return m_FieldDesc[type]; |
|
|
|
|
} |
|
|
|
|
Dictionary<string, string> dic = new Dictionary<string, string>(); |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
PropertyInfo[] peroperties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance); |
|
|
|
|
if (peroperties != null) |
|
|
|
|
{ |
|
|
|
|
foreach (PropertyInfo property in peroperties) |
|
|
|
|
{ |
|
|
|
|
object[] objs = property.GetCustomAttributes(typeof(DescriptionAttribute), true); |
|
|
|
|
if (objs.Length > 0) |
|
|
|
|
{ |
|
|
|
|
var desc = ((DescriptionAttribute)objs[0]).Description.Trim(); |
|
|
|
|
if (!dic.ContainsKey(desc)) |
|
|
|
|
{ |
|
|
|
|
dic.Add(desc, property.Name); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
dic[desc] = property.Name; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch //(Exception ex) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
lock (m_FieldDesc) |
|
|
|
|
{ |
|
|
|
|
if (!m_FieldDesc.ContainsKey(type)) |
|
|
|
|
m_FieldDesc.Add(type, dic); |
|
|
|
|
} |
|
|
|
|
return dic; |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
} |
|
|
|
|