zoukankan      html  css  js  c++  java
  • 特性与元数据

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace chap2_1_7
    {
        class Program
        {
            static void Main(string[] args)
            {
                HR hr = new HR();
                Employee employee = new Employee();
                hr.ToSalary(employee);
                Console.ReadKey();
            }
        }
        public enum TransferSourceType//转账类型
        { 
            Salary,
            Reimburse,
            Loan
        }
        [AttributeUsage(AttributeTargets.Parameter)]
        public class TransferSource : Attribute//转账元数据
        {
            public TransferSourceType TransferType { get; set; }
        }
        public partial class Employee//员工实体
        {
            public void PaySalary([TransferSource(TransferType = TransferSourceType.Salary)] int toNumber)
            { 
                //直接汇入员工银行卡
                Console.WriteLine("收到工资:"+toNumber);
            }
            public void PayReimburse([TransferSource(TransferType = TransferSourceType.Salary)] int toNumber)
            {
                //直接汇入员工银行卡
                Console.WriteLine("收到工资:" + toNumber);
            }
            public void PayLoan([TransferSource(TransferType = TransferSourceType.Salary)] int toNumber)
            {
                //直接汇入员工银行卡
                Console.WriteLine("收到工资:" + toNumber);
            }
        }
        public class HR
        {
            public void ToSalary(Employee employee)
            {
                var transferSource = typeof(Employee).GetMethod("PaySalary").GetParameters()[0].GetCustomAttributes(false)[0] as TransferSource;
                switch (transferSource.TransferType)
                {
                    case TransferSourceType.Salary:
                        {
                            employee.PaySalary(6000);//发工资
                        }break;
                    case TransferSourceType.Reimburse:
                        {
                            employee.PayReimburse(500);//报销                        
                        }break;
                    case TransferSourceType.Loan:
                        {
                            employee.PayLoan(20000);//借款
                        }break;
                }
            }
        }
    }
  • 相关阅读:
    关于Python3中venv虚拟环境
    Python爬虫番外篇之关于登录
    站在圈外看待小米公司发展史
    Python爬虫从入门到放弃(十九)之 Scrapy爬取所有知乎用户信息(下)
    Python爬虫从入门到放弃(十八)之 Scrapy爬取所有知乎用户信息(上)
    Python爬虫番外篇之Cookie和Session
    Python爬虫从入门到放弃(十七)之 Scrapy框架中Download Middleware用法
    Python爬虫从入门到放弃(十六)之 Scrapy框架中Item Pipeline用法
    openstack的网络、子网、端口的关系
    openstack之安全组管理
  • 原文地址:https://www.cnblogs.com/sulong/p/4917100.html
Copyright © 2011-2022 走看看