【.NET】简单使用Description特性
生活随笔
收集整理的這篇文章主要介紹了
【.NET】简单使用Description特性
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在使用處引入包using System.ComponentModel;
在類成員前添加特性,如
public class A{[Description("姓名")]public string name {get;set;} }使用時
//獲取類A的元數據數組 System.Reflection.PropertyInfo[] propertyInfos = typeof(A).GetProperties() foreach(var item in propertyInfos ){ //獲取成員描述DescriptionAttribute customAttribute = (DescriptionAttribute)Attribute.GetCustomAttribute(item, typeof(DescriptionAttribute)); //name值為姓名 string name = customAttribute.Description; }總結
以上是生活随笔為你收集整理的【.NET】简单使用Description特性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 舒亦梵:4.24非农周即将来临,黄金趋势
- 下一篇: 牛客网编程入门刷题简单整理