C# 設置及獲取屬性備注信息 Description


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;                     }             }         }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM