为了账号安全,请及时绑定邮箱和手机立即绑定

如何获取DataAnnotation显示名称的列表

如何获取DataAnnotation显示名称的列表

C#
qq_笑_17 2021-04-02 22:18:50
我有一个带有数据注释的类,需要从显示和属性名称获取字符串列表。我已经尝试了一些方法。在方法GetAttributesNames()中。internal class TVSystemViewData : BaseViewData        {            [Display(Name = "BoxType", Description = "")]            public String BoxType { get; set; }            [Display(Name = "BoxVendor", Description = "")]            public String BoxVendor { get; set; }            [Display(Name = "ClientId", Description = "")]            public String ClientId { get; set; }            [Display(Name = "HostName", Description = "")]            public String HostName { get; set; }            [Display(Name = "OSVersion", Description = "")]            public String OSVersion { get; set; }            [Display(Name = "SerialNumber", Description = "")]            public String SerialNumber { get; set; }            internal void GetAttributesNames()            {                var listOfFieldNames = typeof(TVSystemViewData)                .GetProperties()                .Select(x =>  x.GetCustomAttributes(typeof(DisplayAttribute), true))                .Where(x => x != null)                .ToList();            }}
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 188 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信