Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                UserState userState = UserState.Delete;
                // if (userState==UserState.Delete)
                // {
                //     Console.WriteLine("这是删除状态");
                // }
                // else if (userState==UserState.Frozen)
                // {
                //     Console.WriteLine("这是冻结状态");
                // }
                // else
                // {
                //     Console.WriteLine("这是正常状态");
                // }

                Console.WriteLine(userState.GetRemark());
                Console.WriteLine(UserState.Normal.GetRemark());

                Student s = new Student()
                {
                    QQ = 50121
                };
                Console.WriteLine(s.QQ);
                Console.WriteLine(s.Validate());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddJsonFile("appsettings.json", true, true)
                                           .Build();

            try
            {
                Console.WriteLine("****************Attribute + AOP");
                {
                    Student stu = new Student();
                    stu.Id   = 123;
                    stu.Name = "Ivan";

                    stu.QQ = 1234556;
                    //stu.Study();
                    //stu.Answer("Ivan");
                    Manager.Show(stu);

                    stu.QQ = 1234;
                    Manager.Show(stu);
                }

                {
                    UserState userState = UserState.Normal;

                    // if (userState == UserState.Normal) Console.WriteLine("正常");
                    Console.WriteLine(userState.GetRemark());
                }
                {
                    UserState userState = UserState.Frozen;

                    // if (userState == UserState.Normal) Console.WriteLine("正常");
                    Console.WriteLine(userState.GetRemark());
                }

                {
                    UserState userState = UserState.Deleted;

                    // if (userState == UserState.Normal) Console.WriteLine("正常");
                    Console.WriteLine(userState.GetRemark());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                //throw;
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("欢迎来到.net高级班vip课程,今天的内容是特性和AOP");
                {
                    Student student = new Student();
                    student.Id   = 123;
                    student.Name = "MrSorry";
                    student.QQ   = 123456;
                    student.Study();
                    string result = student.Answer("Eleven");


                    Manager.Show(student);

                    student.Name = "布墨";
                    student.QQ   = 9999;
                    Manager.Show(student);
                }
                {
                    UserState userState = UserState.Normal;
                    //if (userState == UserState.Normal)
                    //{
                    //    Console.WriteLine("正常状态");
                    //}
                    //else if (userState == UserState.Frozen)
                    //{ }
                    //else
                    //{ }
                    Console.WriteLine(userState.GetRemark());
                    Console.WriteLine(RemarkExtension.GetRemark(userState));
                }
                {
                    Console.WriteLine(UserState.Frozen.GetRemark());
                    Console.WriteLine(UserState.Deleted.GetRemark());
                }
                {
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.Read();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("=====In class exer of Attribute=========");

            try
            {
                {
                    Student student = new Student();
                    student.Id   = 123;
                    student.Name = "MrSorry";

                    student.Study();
                    string result = student.Answer("Eleven");

                    //Validate a right QQ number of the student
                    student.QQ = 123456;
                    Manager.Show(student);

                    //Validate a wrong QQ number of the student
                    student.Name = "Jason";
                    student.QQ   = 9999;
                    Manager.Show(student);
                }
                {
                    UserState userState  = UserState.Normal;
                    UserState userState1 = UserState.Frozen;
                    Console.WriteLine(userState.GetRemark());
                    Console.WriteLine(userState1.GetRemark());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.Read();
        }