Serialize / deserialize / whole object, only a part of the object

  • Thread starter Thread starter Markus Freitag
  • Start date Start date
M

Markus Freitag

Guest
Hello,
First
I serialize a class with subclasses. Well so far.

[XmlRoot("ORDER")]
public class Order
{
public class Batch
{
[XmlAttribute("batchID")]
public string BatchID { get; set; }
[XmlAttribute("quantity")]
public int Quantity { get; set; }
}

[XmlAttribute("orderNumberScan")]
public string OrderNumberScan { get; set; }

[XmlArray("BATCHES")]
[XmlArrayItem("BATCH")]
//[XmlElement("BATCH")]
public List<Batch> CurrentListBatches;


<ORDER orderNumberScan="0815" >
<CurrentProduct product="Receiver" manufactor="Sony" />
<BATCHES>
<BATCH batchID="Charge 001" quantity="100" />
<BATCH batchID="Charge 002" quantity="200" />
<BATCH batchID="003" quantity="99" />
<BATCH batchID="Charge 004" quantity="131" />
</BATCHES>
</ORDER>
I would now like to serialize a part and save it as a file.
The result is.

<ArrayOfBatch>
<Batch batchID="Charge 001" quantity="100" />
<Batch batchID="Charge 002" quantity="200" />
<Batch batchID="003" quantity="99" />
<Batch batchID="Charge 004" quantity="131" />
</ArrayOfBatch>
Where does the element name ArrayOfBatch come from?
How can I rename it to batches?

Thank you for suggesting solutions in advance.
Second


protected static object LockBatches = new object();

lock (LockBatches)
{
SaveXML(currentBatches, CurrentOrder.CurrentListBatches);
}

lock (LockBatches)
{
CurrentOrder.CurrentListBatches = DeserializeXML(currentBatchesFile);
}


The list is filled during the process by UI and emptied by the process flow.
In the same application cannot be read and written at the same time.
How can I solve this? Is this correct? Can I use one static object?
Best regards Markus

Continue reading...
 
Back
Top