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