C# 設置及獲取屬性備注信息 Description
1.設置
using System.ComponentModel;
public class List_ParamsModel
{
[Description("開始時間")] [Description("結束時間")]
public string searchDateEnd { get; set; }
}
2.獲取
using System.Reflection;
using System.ComponentModel;
/// <summary> /// </summary> /// <returns></returns> { //Type type = typeof(List_ParamsModel);//model.GetType() System.Reflection.PropertyInfo[] properties = model.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); { } { { object value = property.GetValue(model, null); //值 object[] objs = property.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), true);
if (value != null && !string.IsNullOrEmpty(value.ToString()) && objs.Length > 0 && ((System.ComponentModel.DescriptionAttribute)objs[0]).Description != null) des = ((System.ComponentModel.DescriptionAttribute)objs[0]).Description; } } }