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;
                }
            }
        }
    }
  • 相关阅读:
    从请假日期列表中取得请假起止日期
    存储过程编写经验和优化措施
    安装IE8不能调试VS2003的解决办法
    javascript驗證若干DropDownList是否有選择
    欢迎光临C/S框架网 www.csframework.com
    C#开发框架钢铁贸易进销存系统演示视频
    基于.Net C/S结构系统开发框架V2.2正式发布!
    C#.NET Winform+WebService开发框架完整版本
    C#.Net C/S快速开发框架V2.2版本介绍
    专注C# .Net C/S结构系统开发框架,C/S框架网
  • 原文地址:https://www.cnblogs.com/sulong/p/4917100.html
Copyright © 2011-2022 走看看