Kan*_*ini 0 c# arrays dictionary
我可以使用Dictionary对象数组吗?
我有一个XML,我想修改.我要使用的数据结构是这样的 -
Dictionary<element, Dictionary<attr, value>>
Run Code Online (Sandbox Code Playgroud)
element - 是我要修改的元素attr - 我要更新值的属性值 - 我要更新的值
<Parents>
<Parent id="ParentA" description="New">
<Children>
<Child name="ChildA" />
</Children>
</Parent>
</Parents>
Run Code Online (Sandbox Code Playgroud)
我想通过以下内容
Dictionary<string, string> dict_Attributes1=new Dictionary<string, string>();
Dictionary<string, string> dict_Attributes2=new Dictionary<string, string>();
dict_Attributes1.Add("id", "ParentB");
dict_Attributes1.Add("description", "Old");
dict_Attributes2.Add("name", "ChildB");
Dictionary<string, Dictionary<string, string>> dict_Elements = new Dictionary<string, Dictionary<string, string>>();
dict_Elements.Add(".", dict_Attributes1);//To update the Element
dict_Elements.Add("Children/Child", dict_Attributes2);//To update the Children's Attributes
Run Code Online (Sandbox Code Playgroud)
让我们假设我已经确定我要更新其父ID为ParentA的父.
现在,我在这里创建dict_Attributes1,dict_Attributes2等,有没有一种方法可以将它们存储在(动态,大小未知的编译时)Dictionary对象数组中?
或者,是否有更好的方法 - 1.修改Selected XElement的属性及其子属性?
编辑
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<Environments>
<Environment id="Master" description="MasterSystem">
<Systems>
<DefaultSystem systemName="Master" server="http://localhost" />
</Systems>
</Environment>
</Environments>
</Configuration>
Run Code Online (Sandbox Code Playgroud)
现在,当用户更改id和描述时,我想用新值更新此XML文件.在更改id和description(从用户获取)时,我想更新systemName以及相同的id值.
如果新的id是"Development"并且描述是"DevelopmentSystem",
输出XML应该是
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<Environments>
<Environment id="Development" description="DeveloperSystem">
<Systems>
<DefaultSystem systemName="Development" server="http://localhost" />
</Systems>
</Environment>
</Environments>
</Configuration>
Run Code Online (Sandbox Code Playgroud)
对的,这是可能的.我不确定你需要哪些,但他们都使用List<T>
:
var list = new List<Dictionary<string, string>>();
Run Code Online (Sandbox Code Playgroud)
要么:
var list = new List<Dictionary<string, Dictionary<string, string>>>();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7836 次 |
最近记录: |