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.