• CSharp: Adapter Pattern in donet 6


        /// <summary>
        /// 适配器模式 亦称: 封装器模式、Wrapper、Adapter   Adapter Pattern
        /// </summary>
        public class Employee
        {
    
            /// <summary>
            /// 
            /// </summary>
            public int Id { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string Name { get; set; } = string.Empty;
            /// <summary>
            /// 
            /// </summary>
            public decimal Salary { get; set; }
        }
    
        /// <summary>
        /// 适配器模式 亦称: 封装器模式、Wrapper、Adapter   Adapter Pattern
        /// </summary>
        public class HRSystem
        {
    
            /// <summary>
            /// 
            /// </summary>
            /// <returns></returns>
            public string[,] GetEmployeesInfo() =>
                new string[4, 3]
                {
                { "1", "GeovinDu", "10001" },
                { "2", "geovindu", "10002" },
                { "3", "涂聚文", "10003" },
                { "4", "geovindu", "10004" },
                };
        }
    
        /// <summary>
        /// 适配器模式 亦称: 封装器模式、Wrapper、Adapter   Adapter Pattern
        /// </summary>
        public interface ISalaryProcessor
        {
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="rawEmployees"></param>
            void ProcessSalaries(string[,] rawEmployees);
        }
    
      /// <summary>
        /// 适配器模式 亦称: 封装器模式、Wrapper、Adapter   Adapter Pattern
        /// </summary>
        public class HRSystemAdapter : ISalaryProcessor
        {
    
            /// <summary>
            /// 
            /// </summary>
            private readonly ThirdPartyBillingSystem _thirdPartyBillingSystem;
            /// <summary>
            /// 
            /// </summary>
            public HRSystemAdapter()
            {
                _thirdPartyBillingSystem = new ThirdPartyBillingSystem();
            }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="rawEmployees"></param>
            public void ProcessSalaries(string[,] rawEmployees)
            {
                var employeesForProcessing = PrepareEmployeesForSalaryProcessing(rawEmployees);
                _thirdPartyBillingSystem.ProcessSalary(employeesForProcessing);
            }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="rawEmployees"></param>
            /// <returns></returns>
            private static List<Employee> PrepareEmployeesForSalaryProcessing(string[,] rawEmployees)
            {
                var employeesForProcessing = new List<Employee>();
    
                for (var i = 0; i < rawEmployees.GetLength(0); i++)
                {
                    var id = string.Empty;
                    var name = string.Empty;
                    var salary = string.Empty;
    
                    for (var j = 0; j < rawEmployees.GetLength(1); j++)
                    {
                        switch (j)
                        {
                            case 0:
                                id = rawEmployees[i, j];
                                break;
                            case 1:
                                name = rawEmployees[i, j];
                                break;
                            default:
                                salary = rawEmployees[i, j];
                                break;
                        }
                    }
    
                    var employee = new Employee
                    {
                        Id = Convert.ToInt32(id, CultureInfo.InvariantCulture),
                        Name = name,
                        Salary = Convert.ToDecimal(salary, CultureInfo.InvariantCulture),
                    };
                    employeesForProcessing.Add(employee);
                }
    
                Console.WriteLine("适配器将雇员数组转换为雇员列表...");
    
                return employeesForProcessing;
            }
        }
    
    
        /// <summary>
        /// 适配器模式 亦称: 封装器模式、Wrapper、Adapter   Adapter Pattern
        /// </summary>
        public class ThirdPartyBillingSystem
        {
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="employees"></param>
            public void ProcessSalary(List<Employee> employees)
            {
                foreach (var employee in employees)
                {
                    Console.WriteLine($"工号: {employee.Salary} 工资记入 {employee.Name}' 一个账号.");
                }
            }
        }
    

      

    调用:

     Geovin.Du.DuAdapter.BillingSystem.BillingSystemExecutor.Execute();
    

      

    输出:

    适配器模式 Adapter Pattern: Billing system Demo
    --------------------------------------------------
    适配器将雇员数组转换为雇员列表...
    工号: 10001 工资记入 GeovinDu' 一个账号.
    工号: 10002 工资记入 geovindu' 一个账号.
    工号: 10003 工资记入 涂聚文' 一个账号.
    工号: 10004 工资记入 geovindu' 一个账号.
    

      

    注册包 下 录屏插件

    https://docs.unity3d.com/cn/2022.1/Manual/com.unity.recorder.html
    https://learn.unity.com/tutorial/working-with-unity-recorder#6000f436edbc2a3c53b3d806

    https://github.com/egemenertugrul/wolf3d-readyplayerme-threejs-boilerplate
    https://threejs.org/examples/webgl_loader_fbx
    https://egemenertugrul.github.io/about/
    https://egemenertugrul.github.io/wolf3d-readyplayerme-threejs-boilerplate/
    https://readyplayer.me/developers
    https://github.com/readyplayerme
    https://github.com/brunoimbrizi/tutorial-threejs-mixamo

    Mixamo\

    https://www.mixamo.com/#/

    https://assetstore.unity.com/

  • 相关阅读:
    本来一行可以代替的树节点搜索
    mssql 重新开始标识
    TabContainer实现服务器端回传
    CSS中图片路径的问题
    Javascript在IE下设置innerHTML时出现"未知的运行时错误"
    sql union和union all的用法及效率
    关于动态添加TabPanel遇到的问题以及思考
    关于linq to sql调用存储过程,出现"无法枚举查询结果多次"的问题
    SQL Server 2005连接服务器时的26号错误解决!
    SQL 2000和2005 获取两表的差集
  • 原文地址:https://www.cnblogs.com/geovindu/p/16885186.html
Copyright © 2020-2023  润新知