Bonjour,
Je n'arrive pas à déserialiser une liste de couleurs (la sérialisation semble fonctionner). Voici la classe que je souhaite sérialiser / désérialiser :
Un exemple de sérialisation me donne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public class Param { public string name; public int age; public List<string> friends; [XmlIgnoreAttribute()] public List<Color> colors; public List<string> htmlColors { get { List<String> res = new List<string>(); foreach (Color color in colors) { res.Add(ColorTranslator.ToHtml(color)); } return res; } set { colors = new List<Color>(); foreach (String color in value) { colors.Add(ColorTranslator.FromHtml(color)); } } } public Param() { } }
Cela me convient mais lors de la désérialisation de cette chaine, je ne comprends pas pourquoi, c'est le getter de la propriété htmlColors qui est appelé au lieu du setter...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 <?xml version="1.0" encoding="utf-16"?><Param xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><name>Bob</name><age>15</age><friends><string>Gérard</string><string>Emile</string><string>Jean</string></friends><htmlColors><string>#FF0000</string><string>#FFFF00</string></htmlColors></Param>
Je sais que je pourrais implémenter IXmlSerializable et définir manuellement ReadXml() mais je demande à tout hasard si quelqu'un aurait une solution pour éviter cela car j'ai de nombreuses classes de ce type à sérializer.
Merci !
Partager