G
Guest
I am using C# in Visual Studio 2003.
I would like to serialize a class that contains, amongst other things,
public delegate void DocumentsPreferencesChange(object env, Documents e);
public event DocumentsPreferencesChange OnDocumentsPreferencesChange;
However, as it stands, the classes containing any methods/delegates that have been added to OnDocumentsPreferencesChange also have to be serializable: this I do not want.
I do not actually need OnDocumentsPreferencesChange serialized, so would like to be able to use the NonSerializable attribute as follows:
[NonSerializable] public event DocumentsPreferencesChange OnDocumentsPreferencesChange;
Unfortunately, this gives the compile-time error:
'"Attribute 'NonSerialized;' is not valid on this declaration type. It is valid on 'field' declarations only"
I can get round the problem by setting OnDocumentsPreferencesChange to null before serialization and restoring it afterwards, but this seems messy.
Is there a better way?
Any help would be appreciated.
I would like to serialize a class that contains, amongst other things,
public delegate void DocumentsPreferencesChange(object env, Documents e);
public event DocumentsPreferencesChange OnDocumentsPreferencesChange;
However, as it stands, the classes containing any methods/delegates that have been added to OnDocumentsPreferencesChange also have to be serializable: this I do not want.
I do not actually need OnDocumentsPreferencesChange serialized, so would like to be able to use the NonSerializable attribute as follows:
[NonSerializable] public event DocumentsPreferencesChange OnDocumentsPreferencesChange;
Unfortunately, this gives the compile-time error:
'"Attribute 'NonSerialized;' is not valid on this declaration type. It is valid on 'field' declarations only"
I can get round the problem by setting OnDocumentsPreferencesChange to null before serialization and restoring it afterwards, but this seems messy.
Is there a better way?
Any help would be appreciated.