c# - deserialize `Dictionary<string, Tuple<string, List<string>>>` from custom XML using XElement -


i have dictionary<string, tuple<string, list<string>>> email in want write xml (serialize) , load xml dictionary.

i got write xml such:

public void writetoxml(string path) {   var xelem = new xelement(     "emailalerts",     email.select(x => new xelement("email", new xattribute("h1", x.key),                  new xattribute("body", x.value.item1),                  new xattribute("ids", string.join(",", x.value.item2))))                  );   xelem.save(path); } 

but i'm stuck on loadxml takes xml path , loads dictionary inside email class

this have far:

public void loadxml(string path) {   var xelem2 = xelement.parse(path);   var demail = xelem2.descendants("email").todictionary(x => (string)x.attribute("h1"),                (x => (string)x.attribute("body"),                 x => (string)x.attribute("body"))); } 

background information xml should this

<emailalerts>    <email h1='test1' body='this test' ids='1,2,3,4,5,10,11,15'/> </emailalerts> 

try this:

var str = @"<emailalerts>                 <email h1='test1' body='this test' ids='1,2,3,4,5,10,11,15'/>             </emailalerts>";      var xml = xelement.parse(str);   var result = xml.descendants("email").todictionary(     p => p.attribute("h1").value,      p => new tuple<string, list<string>>(         p.attribute("body").value,          p.attribute("ids").value.split(',').tolist()     ) ); 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -