Re: Serialize/DeSerialize Generics List
- From: "Martin Z" <martin.zarate@xxxxxxxxx>
- Date: 17 Oct 2006 10:37:17 -0700
AFAIK, the way that the deserialize operation of XML Arrays works is
that it constructs an array object (not a List<>) from scratch and
assigns it - meanwhile deserialization requires only an IEnumerable.
Your List<> works fine for deserializing since it's an IEnumerable, bu
not the other way because it's not an Array.
I might be wrong about this - but that's just he behaviour I'm
observing. Perhaps providing a public Array-based property that is
converted to-and-from your hidden List property (converting from lists
to arrays and vice versa is pretty simple) - then just serialize your
Array.
Joe wrote:
Hi
I have a Generics List in a PropertyGrid
I am able to Serialize it to XML but when I try to deserialize back to the
class of the PropertyGrid
The Constructor doesn't seem to fire to reload the saved settings
Can anyone see something that I have missed ?
Class of values
----------------
[XmlRoot("ValueString")]
public class ValueString
{
private string upper = "uppervalue";
private string lower = "lowervalue";
public ValueString()
{
}
public ValueString(string sUpper, string sLower)
{
upper = sUpper
lower = sLower;
}
[XmlElement("Upper")]
public string Upper
{
get { return upper; }
set { upper = value; }
}
[XmlElement("Lower")]
public string Lower
{
get { return lower; }
set { lower = value; }
}
}
PropertGrid Class
----------------
private List<ValueString> myValues = new List<ValueString>();
myValues.Add("upper1","lower1");
myValues.Add("upper2","lower2");
[Category("Misc")]
[Browsable(false)]
[XmlArrayItem("ValArray")]
public List<ValueString> ValuesStr
{
get
{
return myValues
}
set
{
myValues = value;
}
}
xml serialized from Class
-----
<ValuesStr>
<ValArray>
<Upper>upper1</Upper>
<Lower>lower1</Lower>
</ValArray>
<ValArray>
<Upper>upper2</Upper>
<Lower>lower2</Lower>
</ValArray>
</ValuesStr>
.
- Follow-Ups:
- Re: Serialize/DeSerialize Generics List
- From: Martin Z
- Re: Serialize/DeSerialize Generics List
- References:
- Serialize/DeSerialize Generics List
- From: Joe
- Serialize/DeSerialize Generics List
- Prev by Date: Re: How to pass data from a class data member to that class' display m
- Next by Date: Re: Disposing Objects?
- Previous by thread: Serialize/DeSerialize Generics List
- Next by thread: Re: Serialize/DeSerialize Generics List
- Index(es):
Relevant Pages
|