获取model的自定义特性

class Program
    {
        static void Main(String[] args)
        {
            var t = typeof(A);
            var pName = t.GetProperty("Name");
            //4.0或以上版本
            var displayName = pName.GetCustomAttribute<DisplayNameAttribute>();
            Console.WriteLine(displayName.DisplayName);
            Console.ReadKey();
        }
    }


    public class A
    {
        [DisplayName("张三")]
        public String Name { get; set; }
    }

  

posted @ 2018-12-01 09:20  ZaraNet  阅读(340)  评论(0编辑  收藏  举报