Пример #1
0
        static void Main(string[] args)
        {
            StudentVip vip = new StudentVip {
                Id   = 123,
                Name = "小孙"
            };

            ManagerCenter.ManagerStudent <StudentVip>(vip);
            Console.WriteLine("Hello World!");
        }
        //
        public static bool Validate(StudentVip student)
        {
            Type type = student.GetType();

            //type.GetCustomAttributes

            foreach (var prop in type.GetProperties())
            {
                if (prop.IsDefined(typeof(SalaryAttribute), true)) // 这里先判断  是为了提高性能
                {
                    object ovale = prop.GetValue(student);
                    foreach (SalaryAttribute attribute in prop.GetCustomAttributes(typeof(SalaryAttribute), true)) // 获取特性的实例  上面先判断之后,再获取实例
                    {
                        return(attribute.Validate(ovale));
                    }
                }

                //List<Student>
            }
            return(false);
        }
Пример #3
0
 public void GetVideoVip(StudentVip studentVip)
 {
     Console.WriteLine("免费获取全套的公开课视频代码合集");
 }
Пример #4
0
 public void GetVideoVip(StudentVip studentVip)
 {
     Console.WriteLine("继续免费获取任何视频课件代码");
 }
Пример #5
0
 public void GetVideoVip(StudentVip studentVip)
 {
     Console.WriteLine("获取公开课代码合集");
 }