Prevent events from being serialized

  • Thread starter Thread starter Lance
  • Start date Start date
L

Lance

Is there a way to prevent events from being serialized?
For example, I have a serializable class with a Public
property called "Name". The property returns a Protected
string called "_Name". Also, the class has an event
called "NameChanged" that is fired (via the OnNameChanged
method) whenever "_Name" changes.

Ok, enough of that name calling. When I serialize the
class using XML I get a line like the following:

<NameChangedEvent xsi:null="1" />

Is there a way to prevent this line from appearing? I
tried putting <System.NonSerialized()> before NameChanged
but this causes a compile error. Also, is there a reason
why I would want that line to appear?

Thank you,
Lance
 
Hi Lance, an Event is a glorified delegate. What's being (or trying to be)
stored is the value of the delegate method. There's no need to worry about
it... is it really that bad?

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"


: Is there a way to prevent events from being serialized?
: For example, I have a serializable class with a Public
: property called "Name". The property returns a Protected
: string called "_Name". Also, the class has an event
: called "NameChanged" that is fired (via the OnNameChanged
: method) whenever "_Name" changes.
:
: Ok, enough of that name calling. When I serialize the
: class using XML I get a line like the following:
:
: <NameChangedEvent xsi:null="1" />
:
: Is there a way to prevent this line from appearing? I
: tried putting <System.NonSerialized()> before NameChanged
: but this causes a compile error. Also, is there a reason
: why I would want that line to appear?
:
: Thank you,
: Lance
 
Thanks for the info.
...is it really that bad?

No, but its not that good either. If there is an easy
fix (e.g., System.NonSerialized) then I would like to
utilize it.

Thanks again,
Lance
 
Back
Top