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? 7 1879
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?
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?
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?
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?
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?
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?
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?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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....
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |