反射实例

//你感受一下 一定是类
    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 @ 2015-10-27 16:24  骚年丶勿忘初心。  阅读(186)  评论(0编辑  收藏  举报