上篇文章,我们使用VSCode创建了T.Global解决方案和两个类库工程,接下来我们使用Github Copilot完成代码编写
先说以下业务需求:
- 提供一个公共的本地化组件,支持对数字、货币、时间、日期、度量衡单位、排序的在不同区域下的处理。
一、新建一个II18NService接口
这里我们使用了以下Prompt
VSCode中,请帮我在T.Core.i10n.SPI工程下新增接口Ii10nService.cs,这个接口中包含以下方法DoubleToString(double value),DecimalToString(decimal value),FloatToString(float value),DateTimeToString(DateTime time)

GitHub Copilot返回的建议是

请把Ii10nService接口中每个方法增加一个多态方法,这个多态方法增加一个参数CultureInfo,请重新给出Ii10nService接口的代码

请为每个方法增加注释

二、新增度量衡服务接口
这里,给到Github Copilot的Prompt:
请再新增一个度量衡服务接口,IMeasurementService.cs, 这个接口中包含以下方法:转换为英寸、转换为英里、转换为英尺,转换为厘米,转换为千米,转换为公里,转换为克,转换为千克,转换为功率,转换为电流,转换有电压等方法,接口和每个方法请添加注释

三、新增一个排序服务类SortService.cs
这里,给到Github Copilot的Prompt:
请再新增一个排序服务类,SortService.cs, 这个类中增加对.NET 各类集合的排序扩展方法,比如说List的扩展排序方法,支持按当前CultureInfo.CompareInfo进行排序

四、VSCode中在工程T.Core.i10n.Service中,添加对T.Core.i10n.SPI的引用
Prompt:VSCode中,如何在工程T.Core.i10n.Service中,添加对T.Core.i10n.SPI的引用

五、 新增一个类MeasurementService.cs
Prompt:在T.Core.i10n.Service工程下新增一个类MeasurementService.cs,这个类是对IMeasurementService接口的实现,每个方法的实现中,请先获取当前的CultureInfo,基于CultureInfo的内容实现方法的逻辑,输出的代码中请带着详细的注释

六、新增一个类I10nService.cs,这个类是对III10nService接口的实现
Prompt:在T.Core.i10n.Service工程下新增一个类I10nService.cs,这个类是对III10nService接口的实现,每个方法的实现中,如果方法中没传人CultureInfo参数,请先获取当前的CultureInfo,基于CultureInfo的内容实现方法的逻辑,输出的代码中请带着详细的注释,
