473,508 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

event syntax question

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?

thanks,
pat
Nov 15 '05 #1
2 1557
Pat,
didn't compile. my question is: what does the 'field:' do? Causes the NonSerializedAttribute to be applied to the underlying field that
is created and not the Event itself. Remember that an event is implemented
in terms of a field & a couple of special methods.

Use ILDASM on the assembly to see specifics.

For info on Attributes & attribute targets see:

http://msdn.microsoft.com/library/de...arpspec_17.asp

Specifically:

http://msdn.microsoft.com/library/de...pspec_17_2.asp

Hope this helps
Jay

"Pat Richey" <ri****@uiuc.edu> wrote in message
news:ez**************@TK2MSFTNGP11.phx.gbl... 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?

thanks,
pat

Nov 15 '05 #2
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
Nov 15 '05 #3

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

Similar topics

18
2850
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
4
4894
by: Pai | last post by:
hello there, I am trying to rersize the window it works find in IE but doea not work with mozilla window.attachEvent(onload,MWSOnLoad); window.onload = function (MWSOnLoad) { alert('hello');...
3
8205
by: Ohad Young | last post by:
Hi, I have an interface with an event. I'd like to explicitly implement the interface by a certain class. However, I received the following error: "An explicit interface implementation of an...
3
1764
by: Wild Wind | last post by:
Hello, I made a post relating to this issue a while back, but I haven't received any answer, so here I am again. I am writing a mixed C++ dll which uses the following declaration: typedef...
7
3252
by: Oisin Grehan | last post by:
Hi, I have a UserControl derived class: <ns:votingbutton runat="server" id="btn1" onclick="votingbuttonclick" /> My question is, what code do I need in place in the codebehind for this to...
4
2108
by: Peter Oliphant | last post by:
I've upgraded my code to VS C++.NET 2005 (Express) using /clr pure. My question is, why is there an exception to the rule in how pointer syntax is done in the event handlers? For example, why is...
1
1094
by: msch-prv | last post by:
I would like to raise the selected event of an objectdatasource (ods) to retrieve some data. I tried to raise this event using a server button. I am at a loss as to how set up the RaiseEvent syntax...
31
2557
by: Scott M. | last post by:
Am I correct in thinking that because C# doesn't have the "Handles" keyword that VB .NET does, we have to register event delegates manually in C#, whereas in VB .NET using "Handles" takes care of...
4
237
by: tshad | last post by:
I am just getting started with events and had a couple of questions on why they do what they do. If you have a textbox and you want to handle an event you can just do: ...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.