Hi All,

Been exploring a technique that utilizes CollectionBase. Because of a
need I need to use manual Serialization and ISerializable rather then
simply the Serializable attribute.

Now the collection (The internal list) normally serializes no problem
with serializable attribute. But with ISerializable I need to use
special constructor and the GetObjectData method of ISerializable
interface to control the serialization and deserialization process.

So I have a constructor like the following one:

public AbstractDataBindingCollection(SerializationInfo info,
StreamingContext context)
{
BinaryFormatter listDeSerializer = new BinaryFormatter();
            MemoryStream listStream;

            listStream =
(MemoryStream)info.GetValue("list",listStream.GetType());
this.List= (IList)listDeSerializer.Deserialize(listStream);
}

This does not compile because this.List is not writable it is a read
only property.

The corresponding GetObjectData compiles:

public virtual void
GetObjectData(System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
{
BinaryFormatter listSerializer =  new BinaryFormatter();
            MemoryStream listStream = new MemoryStream();

            listSerializer.Serialize(listStream,this.List);

            info.AddValue("list",listStream);
}

The alternative that I know of works but I don't like it. The
alternative that I have working is to enumerate through the list and add
all of the individual items and then in the constructor rebuild the
list.


Anyone else have a better way of doing this.


Keith A Franklin
Chief Software Architect
Empowered Software Solutions
Microsoft Gold Certified Partner for Ecommerce Solutions
www.empowered.com

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to