473,385 Members | 1,453 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,385 software developers and data experts.

not wanting to serialize an event

I have a design in place for a .NET app coded in C# in which the
business object drives the appearence of the UI and when the business
object experiences a change, it notifies the various UIs via events .

Problem is, when I tried serializing the business object to a file,
when traversing the tree of referenced objects, it found the event
targets, and tried to serialize my UI object (which is not
serializable). I then said to myself: "simple solution: mark that
event as non serializable" and went ahead to include the
NonSerializable attribute, but the compiler rejected that as saying
that such attribute applies only to "fields" (and I guess an event is
not a field).

Eventually I solved my problem by having a separate object declaring
the events and broadcasting the events, an object I called
EventNotifier, an instance of which is defined in my business object,
which forwards the requests to broadcast a change event to the
notifier object. In the code, I did mark this instance variable as
[NonSerializable], thus the EventNotifier and all of its target
objects (the UI classes) are never serialized.

Used SOAP serializer in C# 1.1.

It fixed the problem, but was wondering if others have better ideas.
Nov 16 '05 #1
1 4411
Hi Alex,

If you declare an event like this:

public event EventHandler SomeEvent;

then the adding/removing of subscribers is handled transparently.
Presumably there's a field somewhere that holds the event subscribers, but
you can't "see" it, so there's no way to slap an attribute onto it.. On the
other hand, you can do something like this:

[NonSerialized]
private EventHandler someEventHandler;
...
public event EventHandler SomeEvent
{
add {someEventHandler = someEventHandler + value;}
remove {someEventHandler = someEventHandler - value;}
}

Regards,
Daniel

"alexis rzewski" <ar******@hotmail.com> wrote in message
news:d2**************************@posting.google.c om...
I have a design in place for a .NET app coded in C# in which the
business object drives the appearence of the UI and when the business
object experiences a change, it notifies the various UIs via events .

Problem is, when I tried serializing the business object to a file,
when traversing the tree of referenced objects, it found the event
targets, and tried to serialize my UI object (which is not
serializable). I then said to myself: "simple solution: mark that
event as non serializable" and went ahead to include the
NonSerializable attribute, but the compiler rejected that as saying
that such attribute applies only to "fields" (and I guess an event is
not a field).

Eventually I solved my problem by having a separate object declaring
the events and broadcasting the events, an object I called
EventNotifier, an instance of which is defined in my business object,
which forwards the requests to broadcast a change event to the
notifier object. In the code, I did mark this instance variable as
[NonSerializable], thus the EventNotifier and all of its target
objects (the UI classes) are never serialized.

Used SOAP serializer in C# 1.1.

It fixed the problem, but was wondering if others have better ideas.

Nov 16 '05 #2

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

Similar topics

5
by: Michel | last post by:
Hi there, What is the best way to serialize unknown data? I have a class that contains a list of parameter objects. The parameter has a value which can be a simple value of a complex class,...
7
by: Lars-Erik Aabech | last post by:
Hi! I've got problems with serializing my collections of business objects. The objects themselves serialize fine, but the collections fail. I've got the following structure: Base collection...
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
0
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
1
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
2
by: films | last post by:
I understand the concept. Serialization of a class will add all the sub-objects of the class to the stream if there are also serializible. So say I have: class Author {
8
by: Andy B | last post by:
I have the following code in a default.aspx web form page_load event. There seems to be a problem with line 5 (NewsArticle.Date = line). //create a news article NewsArticle NewsArticle = new...
5
by: =?Utf-8?B?Qm9uaQ==?= | last post by:
Hi, I have a class to serialize. This class has come properties like this one private myObject _listOf; public myObject listOf { get { if(_listOf==null) {...
9
by: Gillard | last post by:
i get an exeption and i do not know what else to do to continue Dim sdf As New SaveFileDialog With sdf .AddExtension = True .DefaultExt = ".record" .FileName = Now.ToLongDateString .Filter =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.