Pat Richey <ri****@uiuc.edu> wrote:
i'm writing some events that need to be NonSerialized and to get it to
work i ended up doing something like:
[field: NonSerialized]
public event OnEventHandler myEvent;
because
[NonSerialized]
public event OnEventHandler myEvent;
didn't compile. my question is: what does the 'field:' do?
It's an attribute target specifier. From the C# spec:
<quote>
An attribute specified on an event declaration that omits event
accessors can apply to the event being declared, to the associated
field (if the event is not abstract), or to the associated add and
remove methods. In the absence of an attribute-target-specifier, the
attribute applies to the event declaration. The presence of the event
attribute-target-specifier indicates that the attribute applies to the
event; the presence of the field attribute-target-specifier indicates
that the attribute applies to the field; and the presence of the method
attribute-target-specifier indicates that the attribute applies to the
methods.
</quote>
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too