N
nick.fletcher
I have a custom collection which derives from Collection<> which stores
a number of objects. Before each item is added to the collection - an
event which it exposes is hooked by the collection and the re-fired to
its parent.
eg
class MyCollection : Collection<MyType>
{
public AddAnObject(MyType obj)
{
obj.SomeEvent += new eventhandler(obj_somethingChanged);
base.Add(obj);
}
private void obj_somethingChanged(object sender, EventArgs e)
{
Do something.....
}
}
The problem I have is that if you serialise and then deserialise the
collection, the events are no longer connected. You could probably fix
this in the deserialisation constructor but Im using CF and this doesnt
support System.Runtime.Serialisation. I can fix it by manually going
through the collection after it has been created and re-connecting but
does anyone know a better way?
a number of objects. Before each item is added to the collection - an
event which it exposes is hooked by the collection and the re-fired to
its parent.
eg
class MyCollection : Collection<MyType>
{
public AddAnObject(MyType obj)
{
obj.SomeEvent += new eventhandler(obj_somethingChanged);
base.Add(obj);
}
private void obj_somethingChanged(object sender, EventArgs e)
{
Do something.....
}
}
The problem I have is that if you serialise and then deserialise the
collection, the events are no longer connected. You could probably fix
this in the deserialisation constructor but Im using CF and this doesnt
support System.Runtime.Serialisation. I can fix it by manually going
through the collection after it has been created and re-connecting but
does anyone know a better way?