CSharp: Adapter Pattern in donet 6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | /// <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}' 一个账号." ); } } } |
调用:
1 | Geovin.Du.DuAdapter.BillingSystem.BillingSystemExecutor.Execute(); |
输出:
1 2 3 4 5 6 7 | 适配器模式 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
https://www.mixamo.com/#/
https://assetstore.unity.com/
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
分类:
CSharp code
标签:
desgin patterns
, 设计模式
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!