c# - 如何使用 yamldotnet 启用解析 yaml,它接受同名的列表和键值对?
问题描述
我有一个 yaml,以下两种格式都可以接受 -
args:
buildno: 1
gitcommithash: cdc3b19
和
args:
- buildno=1
- gitcommithash=cdc3b19
以目前的YamlDotnet
配置,
[YamlMember(Alias = "args")]
public Dictionary<string, string> Args { get; set; }
当 yaml 的格式为 no 时,我可以解析。1. 如何修改我的YamlDotNet
代码以接受这两种格式?即接受列表以及 Args 字典?
解决方案
The easiest way to do that is to create a class that implements both IDictionary<string, string>
and IList<string>
. You could try inheriting from Dictionary<string, string>
and implement the list interface. I think it would be enough to implement the Add method from IList, where you split the string by the =
character and add to the dictionary.
There are other ways but this is the simplest.
推荐阅读
- google-sheets - 输入日期序列号并保留目标格式
- arrays - 嵌套的 for 循环在 Flutter 中没有按预期工作
- android-studio - Android Studio 模拟器错误:INSTALL_FAILED_NO_MATCHING_ABIS
- python - matplotlib y 轴标签错误
- javascript - Vue:从 v-for 列表中删除项目会留下画布项目
- javascript - 如何在 TypeScript 的 Vue Composition API 中响应式访问当前路由名称?
- azure-sqldw - 获取 Azure Synapse DW 中临时表的列名
- xamarin.forms - Xamarin 表单 - 媒体控件
- sql - 是否可以使用模式匹配从 Oracle SQL 数据库中选择列?
- uart - vxworks 的 UART 环回测试