首页 > 其他 > 详细

特性,元数据

时间:2018-01-14 13:29:45      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:als   ttr   public   color   var   rto   spa   body   sum   

   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);

 

特性,元数据

标签:als   ttr   public   color   var   rto   spa   body   sum   

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

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号