I have one serializable class
[XmlRoot("p")]
public class BatchField
{
private string _type;
private string _value;
[XmlAttribute("type")]
public string Type
{
get { return _type; }
set { _type = value; }
}
[XmlAttribute("value")]
public string Value
{
get { return _value; }
set { _value = value; }
}
}
[XmlRoot("Batch")]
public class Batch
{
private Collection<BatchField> _p;
[XmlElement]
public Collection<BatchField> P
{
get { return _p; }
set { _p = value; }
}
public Batch()
{
_p = new Collection<BatchField>();
}
}
I am able to serialize and serialize it.After Serialization it generates below XML. This XML is good and m able DE-serialize it successfully.
<?xml version="1.0" encoding="utf-8"?>
<Batch>
<P type="Test" value="113" />
<P type="Test1" value="113" />
<P type="Test2" value="113" />
<P type="Test3" value="113" />
<P type="Test4" value="113" />
<P type="Test5" value="113" />
</Batch>
Now My Question is
I want make this P
dynamic. In Some cases it can be Scanner
or in Some cases it can be Codec
. If i change my batch class I would be able to DE-serialize this class w/o any problem. But I want do it with same class structure...No change in naming ...Is it possible ? Or I am going in wrong direction ? If it is possible then please give some hint...
Summary
I want DE-serialize below XML structures with above given batch class.
<?xml version="1.0" encoding="utf-8"?>
<Batch>
<Scanner type="Test" value="113" />
<Scanner type="Test1" value="113" />
<Scanner type="Test2" value="113" />
<Scanner type="Test3" value="113" />
<Scanner type="Test4" value="113" />
<Scanner type="Test5" value="113" />
</Batch>
I am bit new to this concept.
Thanks in Advance SB