I have a class that I want to save in the ViewState for asp.net UserControl. It basically extends the general list in several ways, but also adds some properties, for example.
public class MyListClass: List<MyObject> { public string ExtraData;
MyObject is serializable, with methods implemented as follows:
[Serializable()] class MyObject { public MyObject(SerializationInfo info, StreamingContext ctxt) { Prop1 = (string)info.GetValue("Prop1", typeof(string));
And general lists are essentially serializable. ViewState works fine with List<MyObject> , but I can't figure out how to implement serialization for MyListClass.
Intuitively, what I want to do is something like this:
public MyListClass(SerializationInfo info, StreamingContext ctxt) { ExtraData= (string)info.GetValue("ExtraData", typeof(string)); this = (List<MyClass>)info.GetValues("BaseList",typeof(List<MyClass>)); }
Obviously this will not work. What is the right way to do this?
source share