473,699 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hooking events post deserialisation

I have a custom collection which derives from Collection<whic h 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<MyTy pe>
{
public AddAnObject(MyT ype obj)
{
obj.SomeEvent += new eventhandler(ob j_somethingChan ged);
base.Add(obj);
}

private void obj_somethingCh anged(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 1922
Hi Nick,

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

Implementing IDeserializatio nCallback 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<whic h 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<MyTy pe>
{
public AddAnObject(MyT ype obj)
{
obj.SomeEvent += new eventhandler(ob j_somethingChan ged);
base.Add(obj);
}

private void obj_somethingCh anged(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...@CA PITALStijsma.co m>
wrote:
Hi Nick,

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

Implementing IDeserializatio nCallback 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<whic h 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<MyTy pe>
{
public AddAnObject(MyT ype obj)
{
obj.SomeEvent += new eventhandler(ob j_somethingChan ged);
base.Add(obj);
}
private void obj_somethingCh anged(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***********@i inet.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...@CA PITALStijsma.co m>
wrote:
>Hi Nick,

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

Implementing IDeserializatio nCallback 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<whic h 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<MyTy pe>
{
public AddAnObject(MyT ype obj)
{
obj.SomeEvent += new eventhandler(ob j_somethingChan ged);
base.Add(obj);
}
private void obj_somethingCh anged(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!

IDeserializatio nCallback 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...@CA PITALStijsma.co m>
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...@i inet.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...@CA PITALStijsma.co m>
wrote:
Hi Nick,
I'm afraid you will have to reattach the events:
Implementing IDeserializatio nCallback 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<whic h 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<MyTy pe>
{
public AddAnObject(MyT ype obj)
{
obj.SomeEvent += new eventhandler(ob j_somethingChan ged);
base.Add(obj);
}
private void obj_somethingCh anged(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***********@i inet.net.au wrote:
Still no joy!

IDeserializatio nCallback 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...@CA PITALStijsma.co m>
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...@CA PITALStijsma.co m>
wrote:
Hi Nick,
I'm afraid you will have to reattach the events:
Implementi ng IDeserializatio nCallback 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.flet c...@iinet.net. au wrote:
I have a custom collection which derives from Collection<whic h 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<MyTy pe>
{
public AddAnObject(MyT ype obj)
{
obj.SomeEvent += new eventhandler(ob j_somethingChan ged);
base.Add(obj);
}
private void obj_somethingCh anged(object sender, EventArgs e)
{
Do something.....
}
}
The problem I have is that if you serialise and then deserialise the
collectio n, 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...@CA PITALStijsma.co m>
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...@i inet.net.au wrote:
Still no joy!
IDeserializatio nCallback 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...@CA PITALStijsma.co m>
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...@i inet.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...@CA PITALStijsma.co m>
wrote:
Hi Nick,
I'm afraid you will have to reattach the events:
Implementin g IDeserializatio nCallback 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.a u wrote:
I have a custom collection which derives from Collection<whic h 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<MyTy pe>
{
public AddAnObject(MyT ype obj)
{
obj.SomeEvent += new eventhandler(ob j_somethingChan ged);
base.Add(obj);
}
private void obj_somethingCh anged(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***********@i inet.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...@CA PITALStijsma.co m>
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!
IDeserializat ionCallback is unfortunately a
System.Runtim e.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...@CA PITALStijsma.co m>
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...@CA PITALStijsma.co m>
wrote:
>Hi Nick,
>I'm afraid you will have to reattach the events:
>Implementi ng IDeserializatio nCallback 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.fl etc...@iinet.ne t.au wrote:
>>I have a custom collection which derives from Collection<whic h 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<MyTy pe>
>>{
>> public AddAnObject(MyT ype obj)
>> {
>> obj.SomeEvent += new eventhandler(ob j_somethingChan ged);
>> base.Add(obj);
>> }
>> private void obj_somethingCh anged(object sender, EventArgs e)
>> {
>> Do something.....
>> }
>>}
>>The problem I have is that if you serialise and then deserialise the
>>collectio n, 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
1743
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 deserialising the same sequence of bytes repeatedly, giving the same output string. Let's ignore the text encoding method, as it's not relevant to my question. Right now, I'm using BinaryReader.ReadString() which gives the correct result,...
3
4480
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. Whenever I hook any of the HTMLDocumnetEvent2_Event events like this: HTMLDocumentEvents2_Event DocEvents = this.Browser.Document as HTMLDocumentEvents2_Event ; DocEvents.oncontextmenu += new...
0
1022
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 with event_source("com"), and CB contains a sink object attributed with . In "B.h" I access A's declarations like this: ;
7
1466
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 handler i can find out which control raise it. Thank's
1
1067
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 from what I've read thus far I'm unclear about whether a binary file needs to have been created with serialise before it can be read with deserialise (ie is there some information added to the file) or can deserialise be used with any binary file...
3
1472
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 sources on how this can be done using VB.Net. Have you seen any examples such as this? I am using VB.Net 2005 Professional, but any .Net examples are welcomed. Thanks!
5
2015
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 same tedium: hooking up events to handlers, and getting data into and out of dialogs. In C++, this is generally handled through code generation and/or macros, but IMO these are brittle and ugly. So my question: Is there a Pythonic way to make...
8
1961
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 hooks. Please (and thankyou), James Randle.
1
1397
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 active one). I have found a nice way to do it with hooking mouse events and reactring accordingly. but I'm affriad that this method is a performances killer for the OS. Is there a better way to do it? How "killer" is my way anyway? Thanks!
0
8615
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9034
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8914
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7750
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.