I developed a workaround for this problem:
[this might be helpful for those who have problems with serializing
NameValueCollection]
For Serializing (MANUAL)
After Serializing the class in an xml file / stream Load the generated
xml using XmlDocument. Then manually added the Attributes to the root
node and write it to the file.
For Deserializing
Add an array of XmlAttribute[] to the class containing the namevalue
collection
when the class is deserialized, those attributes which were not
associated with any property would be added to this array. Write a
function to add element from XmlAttribute array to this name value
collection (filter out any attribute with ":" in it, 'cause there might
be an attribute specifying the type of your object which you might not
want to save in the namevalue collection).
Parag
pa***********@gmail.com wrote:
Can a name value collection be serialized as attributes to the Xml
element of class containing this name value collection?
For eg.
if a class pControl:
[XmlRoot("Control")]
public class pControl {
.....
NameValueCollection _dynamicProperties;
.....
}
if the _dynamicProperties contains:
Key Value
-------------------------------
name tstControl
readonly true
type button
Can I serialize the class pControl as :
<Root>
....
<control name="tstControl" readonly="true" type="button" />
....
</Root>