473,396 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Event method accessibility

According to the CLS specification, the accessibility of the methods for
adding, removing, and raising an event must be identical. There appear to be
a few problems with this:

1) According to the Managed C++ specifications, if one declares a public
event without any attempt to provide one's own event access methods, clearly
the most common case, the compiler generates public add_ and remove_ methods
for the event and a protected raise_ method for the event. This appears to
contradict CLS guideleines for the event and make events declared in MC++
non-compliant with the CLS specification.

2) If I provide my own event member methods signature for the event, I might
want to allow any code to add or remove event handlers for the event, the
common case, while restricting the ability to raise the event to classes in
my own assembly. I can do this by specifying that the accessibility for the
event add_ and remove_ remove methods be made public while the accessibility
for the raise_ method is made public private. If I do this, once again I am
not complying to the CLS specification.

Clearly not complying to the CLS specification will not allow my class to be
used by other .NET languages, which is something which I don't want. However
being able to control which classes are allowed to raise a particular
class's event seems to be a common idiom in computer programming. I know
that .NET makes a big deal about only the class which contains the event
being able to raise the event, but it is clear that designs may call for
other classes being able to raise the event also. This may not have been a
big deal for C++ programmers if the 'friend' functionality were allowed in
the MC++ specification, but it is not. Luckily the concept of assembly
classes having access priveleges which classes outside the assembly do not
have, was added to MC++ specification. However, the CLS guidelines for event
methods having equal accessibility makes it impossible to vary the
accessibility of event methods. Hopefully someone understands this issue and
knows of a way out of this conundrum.
Nov 17 '05 #1
3 1928
Further down in the CIL standard, raise_XXX pattern is defined as:
Pattern: void family raise_<EventName> (Event e)
family is what protected in C++ & C# is, just the cil name. I *think*,
although I can't find a definitive source, that the raise_ method is not an
accessor per se, whereas add and remove are. It isn't very clearly written.
"Edward Diener" <ed******@tropicsoft.com> wrote in message
news:eO****************@TK2MSFTNGP11.phx.gbl...
According to the CLS specification, the accessibility of the methods for
adding, removing, and raising an event must be identical. There appear to be a few problems with this:

1) According to the Managed C++ specifications, if one declares a public
event without any attempt to provide one's own event access methods, clearly the most common case, the compiler generates public add_ and remove_ methods for the event and a protected raise_ method for the event. This appears to
contradict CLS guideleines for the event and make events declared in MC++
non-compliant with the CLS specification.

2) If I provide my own event member methods signature for the event, I might want to allow any code to add or remove event handlers for the event, the
common case, while restricting the ability to raise the event to classes in my own assembly. I can do this by specifying that the accessibility for the event add_ and remove_ remove methods be made public while the accessibility for the raise_ method is made public private. If I do this, once again I am not complying to the CLS specification.

Clearly not complying to the CLS specification will not allow my class to be used by other .NET languages, which is something which I don't want. However being able to control which classes are allowed to raise a particular
class's event seems to be a common idiom in computer programming. I know
that .NET makes a big deal about only the class which contains the event
being able to raise the event, but it is clear that designs may call for
other classes being able to raise the event also. This may not have been a
big deal for C++ programmers if the 'friend' functionality were allowed in
the MC++ specification, but it is not. Luckily the concept of assembly
classes having access priveleges which classes outside the assembly do not
have, was added to MC++ specification. However, the CLS guidelines for event methods having equal accessibility makes it impossible to vary the
accessibility of event methods. Hopefully someone understands this issue and knows of a way out of this conundrum.

Nov 17 '05 #2
Daniel O'Connell wrote:
Further down in the CIL standard, raise_XXX pattern is defined as:
Pattern: void family raise_<EventName> (Event e)
family is what protected in C++ & C# is, just the cil name. I *think*,
although I can't find a definitive source, that the raise_ method is
not an accessor per se, whereas add and remove are. It isn't very
clearly written.
No, it isn't. Especially when it does clearly state in the CLS specification
topic on MSDN that the accessor accessibility for "adding, removing, and
raising an event must be identical." Could this be wrong, and it is only the
"adding and removing" which must have identical accessibility ? Because if
it is correct, every MC++ program which uses the normal "__event
SomeDelegate * eventName;" or "__event returnType
eventName(eventParameters);" is CLS non-compliant, since it generates the
add and remove methods as public and the raise method as protected.

Perhaps MS has clarified this somewhere, but I could not find anything
further on it on their web site. It is scary to think that, according to the
MSDN doc, all MC++ modules which use events are non-compliant with the CLS
and therefore can not be used interchangeably with other .NET languages. I
am sure this can not be the case but the CLS compliant documentation is
clearly saying that it is.


"Edward Diener" <ed******@tropicsoft.com> wrote in message
news:eO****************@TK2MSFTNGP11.phx.gbl...
According to the CLS specification, the accessibility of the methods
for adding, removing, and raising an event must be identical. There
appear to be a few problems with this:

1) According to the Managed C++ specifications, if one declares a
public event without any attempt to provide one's own event access
methods, clearly the most common case, the compiler generates public
add_ and remove_ methods for the event and a protected raise_ method
for the event. This appears to contradict CLS guideleines for the
event and make events declared in MC++ non-compliant with the CLS
specification.

2) If I provide my own event member methods signature for the event,
I might want to allow any code to add or remove event handlers for
the event, the common case, while restricting the ability to raise
the event to classes in my own assembly. I can do this by specifying
that the accessibility for the event add_ and remove_ remove methods
be made public while the accessibility for the raise_ method is made
public private. If I do this, once again I am not complying to the
CLS specification.

Clearly not complying to the CLS specification will not allow my
class to be used by other .NET languages, which is something which I
don't want. However being able to control which classes are allowed
to raise a particular class's event seems to be a common idiom in
computer programming. I know that .NET makes a big deal about only
the class which contains the event being able to raise the event,
but it is clear that designs may call for other classes being able
to raise the event also. This may not have been a big deal for C++
programmers if the 'friend' functionality were allowed in the MC++
specification, but it is not. Luckily the concept of assembly
classes having access priveleges which classes outside the assembly
do not have, was added to MC++ specification. However, the CLS
guidelines for event methods having equal accessibility makes it
impossible to vary the accessibility of event methods. Hopefully
someone understands this issue and knows of a way out of this
conundrum.

Nov 17 '05 #3

"Edward Diener" <ed******@tropicsoft.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Daniel O'Connell wrote:
Further down in the CIL standard, raise_XXX pattern is defined as:
Pattern: void family raise_<EventName> (Event e)
family is what protected in C++ & C# is, just the cil name. I *think*,
although I can't find a definitive source, that the raise_ method is
not an accessor per se, whereas add and remove are. It isn't very
clearly written.
No, it isn't. Especially when it does clearly state in the CLS

specification topic on MSDN that the accessor accessibility for "adding, removing, and
raising an event must be identical." Could this be wrong, and it is only the "adding and removing" which must have identical accessibility ? Because if
it is correct, every MC++ program which uses the normal "__event
SomeDelegate * eventName;" or "__event returnType
eventName(eventParameters);" is CLS non-compliant, since it generates the
add and remove methods as public and the raise method as protected.
I couldn't find this information, I used the ECMA spec, do you have a
reference? In languages like C#, the raise_ method doesn't appear to be
there most of the time(at all?), that and the ECMA spec showing a family
modifer suggests to me that there is a problem with the MSDN documentation. Perhaps MS has clarified this somewhere, but I could not find anything
further on it on their web site. It is scary to think that, according to the MSDN doc, all MC++ modules which use events are non-compliant with the CLS
and therefore can not be used interchangeably with other .NET languages. I
am sure this can not be the case but the CLS compliant documentation is
clearly saying that it is. I wouldn't worry about it much. I prefer to use protected raiser
methods(like OnMyEvent) instead of allowing inheriters to directly access
the event. So I find this to probably not be of much issue if you follow a
similar pattern. In the framework, most events are fired by the base OnXXX
method, which is why you should almost always call the base implementation.


"Edward Diener" <ed******@tropicsoft.com> wrote in message
news:eO****************@TK2MSFTNGP11.phx.gbl...
According to the CLS specification, the accessibility of the methods
for adding, removing, and raising an event must be identical. There
appear to be a few problems with this:

1) According to the Managed C++ specifications, if one declares a
public event without any attempt to provide one's own event access
methods, clearly the most common case, the compiler generates public
add_ and remove_ methods for the event and a protected raise_ method
for the event. This appears to contradict CLS guideleines for the
event and make events declared in MC++ non-compliant with the CLS
specification.

2) If I provide my own event member methods signature for the event,
I might want to allow any code to add or remove event handlers for
the event, the common case, while restricting the ability to raise
the event to classes in my own assembly. I can do this by specifying
that the accessibility for the event add_ and remove_ remove methods
be made public while the accessibility for the raise_ method is made
public private. If I do this, once again I am not complying to the
CLS specification.

Clearly not complying to the CLS specification will not allow my
class to be used by other .NET languages, which is something which I
don't want. However being able to control which classes are allowed
to raise a particular class's event seems to be a common idiom in
computer programming. I know that .NET makes a big deal about only
the class which contains the event being able to raise the event,
but it is clear that designs may call for other classes being able
to raise the event also. This may not have been a big deal for C++
programmers if the 'friend' functionality were allowed in the MC++
specification, but it is not. Luckily the concept of assembly
classes having access priveleges which classes outside the assembly
do not have, was added to MC++ specification. However, the CLS
guidelines for event methods having equal accessibility makes it
impossible to vary the accessibility of event methods. Hopefully
someone understands this issue and knows of a way out of this
conundrum.


Nov 17 '05 #4

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

Similar topics

21
by: news.btinternnet.com | last post by:
I can do this in IE myLink.click(); //Invoking the handler as if the user had clicked on the link themselves. I need to be able to do the same in Netscape Navigator, can anyone help ?
2
by: Marinos Christoforou | last post by:
Sorry if this has been asked before but as an inexperienced wanna-be C# programmer I wondering how to code classes to help build a standard Windows UI. For example to build a common toolbar. I...
6
by: z_learning_tester | last post by:
Hello, I am new to C# and have a quick question. Any replies much appreciated ;-) It is regarding static methods... Are they public by default? I mean it seems like for them to be usable, they...
8
by: paccala | last post by:
Ciao Being google-ing since hours and still I'm not able to solve my problem... I have following hierarchy: class A { public void myMethod(); }
4
by: waltborders | last post by:
Hi, Because the blind are unable to use a mouse, keyboard navigation is key. A major difficulty is that not all windows forms controls are keyboard 'tab-able' or 'arrow-able' or have "tab...
4
by: BC | last post by:
Hi all, Just wondering what are the difference between: public event EventHandler MessageNotify; public EventHandler MessageNotify; A friend told me it's related to the accessibility levels.
1
by: shland | last post by:
This is related to my previous post on "fire click event from serverside code?" Alternately, is there a way to intercept a click event on a control from a referenced .dll, and do some...
3
by: I am Sam | last post by:
Please help. I'm dying here and pulling out the last few remaining elements of my hair over this. I have built a form that will identify and authenticate users. I keep getting the following...
3
by: =?Utf-8?B?TkVXMi5ORVQ=?= | last post by:
I have a static event declared in a C++ ref class, that can then be handled in a VB app. I'm trying to expose the static event through the interface that the C++ ref class implements so the VB app...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.