首页 > Windows开发 > 详细

C# 设置及获取属性备注信息 Description

时间:2021-01-05 15:09:40      阅读:154      评论:0      收藏:0      [点我收藏+]

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

C# 设置及获取属性备注信息 Description

原文:https://www.cnblogs.com/dennyw/p/14235156.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!