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/

posted @ 2022-11-12 23:58  ®Geovin Du Dream Park™  阅读(19)  评论(0编辑  收藏  举报