Exemplo n.º 1
0
        private static void CanWriteCheck(object obj)
        {
            //构造实例
            Attribute checking = new AccountsAttribute(Accounts.Checking);

            //构造应用于类型的特性实例
            Attribute validAccounts = Attribute.GetCustomAttribute(obj.GetType(), typeof(AccountsAttribute), false);


            if ((validAccounts != null) && checking.Match(validAccounts))
            {
                Console.WriteLine("{0} types can write checks.", obj.GetType());
            }
            else
            {
                Console.WriteLine("{0} types can not write checks.", obj.GetType());
            }
        }