473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Hooking events post deserialisation

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?

Nov 24 '06 #1
7 1911
Hi Nick,

I'm afraid you will have to reattach the events:

Implementing IDeserializationCallback on your collection will allow you
to get a callback as soon as deserialization is complete.

Regards,

Wiebe Tijsma
http://www.e-office.com

Hi,ni***********@iinet.net.au wrote:
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?

Nov 24 '06 #2
I thought so much :-( Thanks for the hint on the interface though -
I'll give that a shot

On Nov 24, 10:14 pm, Wiebe Tijsma <wiebeREM...@CAPITALStijsma.com>
wrote:
Hi Nick,

I'm afraid you will have to reattach the events:

Implementing IDeserializationCallback on your collection will allow you
to get a callback as soon as deserialization is complete.

Regards,

Wiebe Tijsmahttp://www.e-office.com

Hi,nick.fletc...@iinet.net.au wrote:
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?
Nov 26 '06 #3
Hi Nick,

You're welcome :)

If I may give an additional advise:

In my opinion, in most situations where events are used, they can be
replaced by a different architectural design using interfaces or
abstract base classes, especially on scenarios where serialization is
involved.

(events are evil :p)

Regards,

Wiebe Tijsma
ni***********@iinet.net.au wrote:
I thought so much :-( Thanks for the hint on the interface though -
I'll give that a shot

On Nov 24, 10:14 pm, Wiebe Tijsma <wiebeREM...@CAPITALStijsma.com>
wrote:
>Hi Nick,

I'm afraid you will have to reattach the events:

Implementing IDeserializationCallback on your collection will allow you
to get a callback as soon as deserialization is complete.

Regards,

Wiebe Tijsmahttp://www.e-office.com

Hi,nick.fletc...@iinet.net.au wrote:
>>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?
Nov 26 '06 #4
Still no joy!

IDeserializationCallback is unfortunately a
System.Runtime.Serialization interface and is not supported under CF.
Wrt your last post - how could I change the architecture such that one
class can asynchronously notify another of an event via an
interface/abstract class. I mean, I could also use a delegate but I end
up with the same problem in that serialization will only serialize
public properties

Many thanks

Nick

On Nov 27, 3:29 am, Wiebe Tijsma <wiebeREM...@CAPITALStijsma.com>
wrote:
Hi Nick,

You're welcome :)

If I may give an additional advise:

In my opinion, in most situations where events are used, they can be
replaced by a different architectural design using interfaces or
abstract base classes, especially on scenarios where serialization is
involved.

(events are evil :p)

Regards,

Wiebe Tijsma

nick.fletc...@iinet.net.au wrote:
I thought so much :-( Thanks for the hint on the interface though -
I'll give that a shot
On Nov 24, 10:14 pm, Wiebe Tijsma <wiebeREM...@CAPITALStijsma.com>
wrote:
Hi Nick,
I'm afraid you will have to reattach the events:
Implementing IDeserializationCallback on your collection will allow you
to get a callback as soon as deserialization is complete.
Regards,
Wiebe Tijsmahttp://www.e-office.com
Hi,nick.fletc...@iinet.net.au wrote:
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?
Nov 26 '06 #5
Hi Nick,

I'm sorry for the wrong information then, I don't use the CF.

Are you using the XmlSerializer? this will only serialize public properties.

The binary serialization will serialize the in-memory representation of
your objects (fields), not the public properties.

What you could do is implement IEnumerable on your object model, and
iterate through your graph querying your object model for your own
custom interface that requires the callback (IMyCallBack) and execute
that recursively as soon as deserialization is complete.

In that case you can also reattach your events.

Best regards,

Wiebe Tijsma
http://www.e-office.com
ni***********@iinet.net.au wrote:
Still no joy!

IDeserializationCallback is unfortunately a
System.Runtime.Serialization interface and is not supported under CF.
Wrt your last post - how could I change the architecture such that one
class can asynchronously notify another of an event via an
interface/abstract class. I mean, I could also use a delegate but I end
up with the same problem in that serialization will only serialize
public properties

Many thanks

Nick

On Nov 27, 3:29 am, Wiebe Tijsma <wiebeREM...@CAPITALStijsma.com>
wrote:
>Hi Nick,

You're welcome :)

If I may give an additional advise:

In my opinion, in most situations where events are used, they can be
replaced by a different architectural design using interfaces or
abstract base classes, especially on scenarios where serialization is
involved.

(events are evil :p)

Regards,

Wiebe Tijsma

nick.fletc...@iinet.net.au wrote:
>>I thought so much :-( Thanks for the hint on the interface though -
I'll give that a shot
On Nov 24, 10:14 pm, Wiebe Tijsma <wiebeREM...@CAPITALStijsma.com>
wrote:
Hi Nick,
I'm afraid you will have to reattach the events:
Implementing IDeserializationCallback on your collection will allow you
to get a callback as soon as deserialization is complete.
Regards,
Wiebe Tijsmahttp://www.e-office.com
Hi,nick.fletc...@iinet.net.au wrote:
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?
Nov 28 '06 #6
Hiya

I actually found a solution

When the collection which holds the objects is deserialized it actually
calls it Add() method on the base class. All I needed to do was
override the add instead of wrapping it and hey presto

Thanks for your help though :-)

On Nov 28, 11:37 am, Wiebe Tijsma <wiebeREM...@CAPITALStijsma.com>
wrote:
Hi Nick,

I'm sorry for the wrong information then, I don't use the CF.

Are you using the XmlSerializer? this will only serialize public properties.

The binary serialization will serialize the in-memory representation of
your objects (fields), not the public properties.

What you could do is implement IEnumerable on your object model, and
iterate through your graph querying your object model for your own
custom interface that requires the callback (IMyCallBack) and execute
that recursively as soon as deserialization is complete.

In that case you can also reattach your events.

Best regards,

Wiebe Tijsmahttp://www.e-office.com

nick.fletc...@iinet.net.au wrote:
Still no joy!
IDeserializationCallback is unfortunately a
System.Runtime.Serialization interface and is not supported under CF.
Wrt your last post - how could I change the architecture such that one
class can asynchronously notify another of an event via an
interface/abstract class. I mean, I could also use a delegate but I end
up with the same problem in that serialization will only serialize
public properties
Many thanks
Nick
On Nov 27, 3:29 am, Wiebe Tijsma <wiebeREM...@CAPITALStijsma.com>
wrote:
Hi Nick,
You're welcome :)
If I may give an additional advise:
In my opinion, in most situations where events are used, they can be
replaced by a different architectural design using interfaces or
abstract base classes, especially on scenarios where serialization is
involved.
(events are evil :p)
Regards,
Wiebe Tijsma
nick.fletc...@iinet.net.au wrote:
I thought so much :-( Thanks for the hint on the interface though -
I'll give that a shot
On Nov 24, 10:14 pm, Wiebe Tijsma <wiebeREM...@CAPITALStijsma.com>
wrote:
Hi Nick,
I'm afraid you will have to reattach the events:
Implementing IDeserializationCallback on your collection will allow you
to get a callback as soon as deserialization is complete.
Regards,
Wiebe Tijsmahttp://www.e-office.com
Hi,nick.fletc...@iinet.net.au wrote:
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?
Nov 28 '06 #7
Ah, so are you using the XmlSerializer then?
ni***********@iinet.net.au wrote:
Hiya

I actually found a solution

When the collection which holds the objects is deserialized it actually
calls it Add() method on the base class. All I needed to do was
override the add instead of wrapping it and hey presto

Thanks for your help though :-)

On Nov 28, 11:37 am, Wiebe Tijsma <wiebeREM...@CAPITALStijsma.com>
wrote:
>Hi Nick,

I'm sorry for the wrong information then, I don't use the CF.

Are you using the XmlSerializer? this will only serialize public properties.

The binary serialization will serialize the in-memory representation of
your objects (fields), not the public properties.

What you could do is implement IEnumerable on your object model, and
iterate through your graph querying your object model for your own
custom interface that requires the callback (IMyCallBack) and execute
that recursively as soon as deserialization is complete.

In that case you can also reattach your events.

Best regards,

Wiebe Tijsmahttp://www.e-office.com

nick.fletc...@iinet.net.au wrote:
>>Still no joy!
IDeserializationCallback is unfortunately a
System.Runtime.Serialization interface and is not supported under CF.
Wrt your last post - how could I change the architecture such that one
class can asynchronously notify another of an event via an
interface/abstract class. I mean, I could also use a delegate but I end
up with the same problem in that serialization will only serialize
public properties
Many thanks
Nick
On Nov 27, 3:29 am, Wiebe Tijsma <wiebeREM...@CAPITALStijsma.com>
wrote:
Hi Nick,
You're welcome :)
If I may give an additional advise:
In my opinion, in most situations where events are used, they can be
replaced by a different architectural design using interfaces or
abstract base classes, especially on scenarios where serialization is
involved.
(events are evil :p)
Regards,
Wiebe Tijsma
nick.fletc...@iinet.net.au wrote:
I thought so much :-( Thanks for the hint on the interface though -
I'll give that a shot
On Nov 24, 10:14 pm, Wiebe Tijsma <wiebeREM...@CAPITALStijsma.com>
wrote:
>Hi Nick,
>I'm afraid you will have to reattach the events:
>Implementing IDeserializationCallback on your collection will allow you
>to get a callback as soon as deserialization is complete.
>Regards,
>Wiebe Tijsmahttp://www.e-office.com
>Hi,nick.fletc...@iinet.net.au wrote:
>>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?
Nov 29 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: drewnoakes | last post by:
I have an application that performs custom deserialisation of object state from byte arrays. This happens very regularly, so needs to be fast. In addition, most of the strings repeat, meaning I'm...
3
by: Rick Strahl [MVP] | last post by:
I'm working on an app that's using the WebBrowser control. I got the control working fine, hooking to the document object. But I've run into a major issue with hooking the Document events....
0
by: Carl Clawson | last post by:
The C++ compiler is choking on what looks like a valid dispinterface method declaration. I have an ATL object "A" that fires COM events, and an object "B" that receives them. CA is attributed...
7
by: Yovi Oktofianus | last post by:
Hi all, is it posible to hook every post back event ? My goal is I want to know which control send post back event to my page before Page.OnLoad event raised. Or at least in Page_Load event...
1
by: John Dann | last post by:
I need to read a binary file (whose structure I know - at least in generic terms) and just learning about how best to do it. Looking at deserialisation this seems to be one direct approach. But...
3
by: Jim | last post by:
I'd like to hook events (like when a user clicks or right-clicks on a link in a web page) to launch a download manager or to open a new window for the link, but I am finding it difficult to find...
5
by: Ryan Ginstrom | last post by:
Apropos recent threads about GUI editors, coming from a Win32/WTL C++ background, I actually like the idea of being able to (easily) create GUIs programmatically. But I still see a lot of the...
8
by: pigeonrandle | last post by:
Hi, Has anyone had any experience with hooking messages in other application windows (like SPY++). I want to listen for WM_MOVE messages, but can only seem to find examples of Keyboard and Mouse...
1
by: Tom Rahav | last post by:
Hello, I try to develop application that runs in the background and suppose to display a small form with menu whenever the user clicks the middle mouse button (also when my application is not the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.