I have class that implement list of custom class. That class also has two properties. But when I serialize that class, XML contains only array of my custom classes but don't contains another two properties. Here is the class:
public class Porudzbina : List<PorudzbenicaStavka>, IEnumerable<SqlDataRecord>
{
public long KomSifra { get; set; }
public Guid KomId { get; set; }
IEnumerator<SqlDataRecord> IEnumerable<SqlDataRecord>.GetEnumerator()
{
var sqlRow = new SqlDataRecord(
new SqlMetaData("rb", SqlDbType.Int),
new SqlMetaData("RobaSifra", SqlDbType.NVarChar, 50),
new SqlMetaData("RobaNaziv", SqlDbType.NVarChar, 100)
);
foreach (PorudzbenicaStavka por in this)
{
sqlRow.SetInt32(0, por.rb);
sqlRow.SetString(1, por.RobaSifra);
sqlRow.SetString(2, por.RobaNaziv);
yield return sqlRow;
}
}
}
and code that I use to serialize it:
XmlSerializer serializer = new XmlSerializer(typeof(Porudzbina));
using (TextWriter writer = new StreamWriter(@"C:\Xmle.xml"))
{
serializer.Serialize(writer, por);
}
and this is XML that I got:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfPorudzbenicaStavka xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<PorudzbenicaStavka>
<rb>1</rb>
<RobaSifra>3702</RobaSifra>
<RobaNaziv>Foullon mlecna cokolada 33% Ecuador 100g</RobaNaziv>
</PorudzbenicaStavka>
<PorudzbenicaStavka>
<rb>2</rb>
<RobaSifra>1182</RobaSifra>
<RobaNaziv>IL Capitano zelena maslina sa paprikom 720g</RobaNaziv>
</PorudzbenicaStavka>
<PorudzbenicaStavka>
<rb>3</rb>
<RobaSifra>1120</RobaSifra>
<RobaNaziv>Kaiser tuna steak sa papricicom u ulju 170g.</RobaNaziv>
</PorudzbenicaStavka>
</ArrayOfPorudzbenicaStavka>
I want my xml contains two properties together with a array of custom class, that I could deserialize it into its original state...