反射-特性

 private void button1_Click(object sender, EventArgs e)
        {
            Say();

        }

        [Obsolete("已过时,请调用SayHi替代")]
        public void Say()
        { 
        }
        public void SayHi()
        {
            MessageBox.Show("Test");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Dog d1 = new Dog();
            Dog d2 = new Dog();

            Type t1= d1.GetType();
            //1.反射 获取dog类 所有 的非继承 的特性对象

          object []obj=  t1.GetCustomAttributes(false);//不获取父类的特性

            //2.反射 获取 Dog类 指定 的特性对象
          object []obj1=  t1.GetCustomAttributes(typeof(NameAttribute),false);
        }


继承Attribute 类 
原文地址:https://www.cnblogs.com/sumg/p/3800976.html