J'ai un problème de désérialisation d'une liste de mon fichier xml. Mes propriétés sont internes, donc j'utilise datacontrerserializer pas xmlserializer.Listes DataContractSerializer et Generic
Mon xml est la suivante
<?xml version="1.0" encoding="utf-8" ?>
<Root xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Root">
<BackgroundColor>
0,0,255
</BackgroundColor>
<RowGap>1</RowGap>
<Table>
<TableHeading>"H1"</TableHeading>
<StartingColumn>A</StartingColumn>
</Table>
<Table>
<TableHeading>"H2"</TableHeading>
<StartingColumn>B</StartingColumn>
</Table>
</Root>
Racine a Liste du tableau. Le ListOfTables n'est pas désérialisé. Les classes sont
[DataContract()]
public class Root
{
[OnDeserialized]
internal void OnSerializingMethod(StreamingContext context)
{
if (Table == null)
{
Table = new List<TableStructure>();
}
}
[DataMember(Name = "RowGap")]
internal int RowGap { get; set; }
[DataMember(Name = "TableHeaderBackgroundColor")]
internal string HdrBackColor { get; set; }
[DataMember()]
internal List<TableStructure> Table { get; set; }
}
[DataContract(Name = "Table", Namespace = "")]
public sealed class TableStructure
{
[DataMember]
public string TableHeading { get; set; }
[DataMember]
public string StartingColumn { get; set; }
}
La méthode desrialize
internal static Root GetSettings()
{
Root settings;
using (FileStream fs = new FileStream("Root.xml", FileMode.Open, FileAccess.Read))
{
using (XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas()))
{
var x = new DataContractSerializer(typeof(Root));
settings = (Root)x.ReadObject(reader);
reader.Close();
fs.Close();
}
}
return settings;
}
Cette exécute sans erreur, mais ne se chargent pas toute information de table. RowGap et la couleur est en cours de chargement
Merci pour votre aide. ça fonctionne maintenant. – MJK