列表我想序列名單列表,但我得到System.InvalidOperationException 在如何序列名單
XmlSerializer xmlSer = new XmlSerializer(List.GetType());
這是我的課
public class ListDevis
{
public ListDevis()
{
list = new BindingList<Devis>();
}
private BindingList<Devis> list;
[XmlArrayItem(ElementName = "Devis", Type = typeof(Devis))]
public BindingList<Devis> List
{
get
{
return list;
}
set
{
list = value;
}
}
public void ChargerList(string xmlFilePath)
{
XmlSerializer xmlSer = new XmlSerializer(List.GetType());
if (File.Exists(xmlFilePath))
{
using (StreamReader streamR = new StreamReader(xmlFilePath))
{
try
{
List = (BindingList<Devis>)xmlSer.Deserialize(streamR);
}
catch (Exception)
{
}
}
}
}
public void SauvegarderList(string xmlFilePath)
{
XmlSerializer xmlSer = new XmlSerializer(typeof(ListDevis));
using (StreamWriter streamW = new StreamWriter(xmlFilePath))
{
xmlSer.Serialize(streamW, List);
}
}
}
public class Devis
{
public Devis()
{
commandes = new BindingList<Commande>();
}
private string code;
private string codeClient;
private DateTime dateDevis;
private BindingList<Commande> commandes;
private string statut;
[DisplayName("Code Devis")]
public string Code
{
get
{
return code;
}
set
{
code = value;
}
}
[DisplayName("Code Client")]
public string CodeClient
{
get
{
return codeClient;
}
set
{
codeClient = value;
}
}
[DisplayName("Date Creation")]
public DateTime DateDevis
{
get
{
return dateDevis;
}
set
{
dateDevis = value;
}
}
[XmlElement(ElementName = "Commandes", Type = typeof(Commande))]
public BindingList<Commande> Commandes
{
get
{
return commandes;
}
set
{
commandes = value;
}
}
[DisplayName("Statut")]
public string Statut
{
get
{
return statut;
}
set
{
statut = value;
}
}
}
public class Commande
{
private string codeProduit;
private string libelle;
private float prixU;
private int qte;
public Commande(string codeProduit, string libelle, float prixU, int qte)
{
this.CodeProduit = codeProduit;
this.Libelle = libelle;
this.PrixU = prixU;
Qte = qte;
}
[XmlElement(DataType = "string", ElementName = "CodeProduit")]
public string CodeProduit
{
get
{
return codeProduit;
}
set
{
codeProduit = value;
}
}
[XmlElement(DataType = "string", ElementName = "Libelle")]
public string Libelle
{
get
{
return libelle;
}
set
{
libelle = value;
}
}
[XmlElement(DataType = "float", ElementName = "Prix")]
public float PrixU
{
get
{
return prixU;
}
set
{
prixU = value;
}
}
[XmlElement(DataType = "int", ElementName = "Qte")]
public int Qte
{
get
{
return qte;
}
set
{
qte = value;
}
}
}
我的全是例外This/ 沒有例外的非系統類型'System.InvalidOperationException'的最終產品dans System.Xml.dll
Informationssupplémentaires:Une erreur s'est produite lors de laréflexiondu type'GestionFacturationCore.ListDevis'。
我有類似的東西 - 這是它是如何完成http://stackoverflow.com/a/40165240/1704458 –
我用這種方法,它沒有工作,我認爲問題是從公開名單名單 –