Re: Serialize/DeSerialize Generics List

Tech-Archive recommends: Fix windows errors by optimizing your registry



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>

.



Relevant Pages

  • Re: Serialize/DeSerialize Generics List
    ... a bit of a brain fart there: I said "Deserialize" when I meant ... "Serialize" a bunch of times. ... from Array. ... converted to-and-from your hidden List property (converting from lists ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: garbage collection problem in large linked lists
    ... Instead all buckets are allocated at once in an array. ... VG.net, which must be very scalable, but only for lists which would normally ... Linked lists require pointer dereferencing in order to traverse. ... When you run out of space, you allocate a new smaller array. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Dict sharing vs. duplication
    ... array to enforce unique keys and I use lists to enforce order. ... API in a page or two of Tcl code, it isn't so much a missing feature ... OpenACS database API which creates a new specialized data structure, ...
    (comp.lang.tcl)
  • Re: Translating python to scheme
    ... Scheme has mutation, and there are reasons to use it. ... confusing when considering a 2d array. ... in other languages: Lisp Lists and Vectors. ...
    (comp.lang.scheme)
  • Re: vasam
    ... // Set the size for long lists in records #2 and #3 only! ... Here is the sequel of my previous post "Variable array sizes as members" ... I was given some advice on how to use malloc and realloc in oder to achieve ...
    (microsoft.public.vc.language)