码迷,mamicode.com
首页 > 其他好文 > 详细

特性,元数据

时间:2018-01-14 13:50:44      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:银行卡   method   bsp   sum   blog   getc   attribute   att   ==   

   public class Employee
    {
        // 只有SourceType== Salary 才转账
        public void TransferToEmployee([TransferSource(TransferType = TransferSourceType.Salary)]int number)
        {
            //汇钱到银行卡
        }
    }
    /// <summary>
    /// 转账类型
    /// </summary>
    public enum TransferSourceType
    {
        Salary,
        Reimburse,
        Loan
    }
  public class HR
    {
        public void ToSalary(Employee employee)
        {
// 使用元数据
var transferSource = typeof(Employee).GetMethod("TransferToEmployee").GetParameters()[0].GetCustomAttributes(false)[0] as TransferSource; if (transferSource.TransferType == TransferSourceType.Salary) { employee.TransferToEmployee(500); } else { employee.TransferToEmployee(0); } } }
        Employee employee = new Employee();
            HR hr = new HR();
            hr.ToSalary(employee);

 

特性,元数据

标签:银行卡   method   bsp   sum   blog   getc   attribute   att   ==   

原文地址:https://www.cnblogs.com/xuyuchen/p/8283094.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!