473,466 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Replacing an event

Hi there,

I wrote a replacement for the native .NET class "FileDialog" with my own
"FileOk" event (triggered when the user selects a file and clicks OK). Let's
say I now want to create a derivative called "MyFileDialog" and replace the
"FileOk" event with a new event called "MyFileOk". Users of this class
should therefore rely on the latter event and not "FileOk" from the base
class. Is it therefore possible to hide the base class' "FileOk" event so
that users can't invoke it. Redefining it as private doesn't help (the base
class version kicks in instead) so the only way I can see is to redefine it
as "public" (using the "new" keyword) and then throwing a
"System.NotImplementedException" (also asserting in the debug version). This
is ugly IMO however so I'm hoping there's a cleaner way. Any advice would be
appreciated. Thanks.
Sep 27 '07 #1
2 1533
On Sep 27, 2:21 pm, "MikeP" <no_spam@_nospam.comwrote:
I wrote a replacement for the native .NET class "FileDialog" with my own
"FileOk" event (triggered when the user selects a file and clicks OK). Let's
say I now want to create a derivative called "MyFileDialog" and replace the
"FileOk" event with a new event called "MyFileOk". Users of this class
should therefore rely on the latter event and not "FileOk" from the base
class. Is it therefore possible to hide the base class' "FileOk" event so
that users can't invoke it. Redefining it as private doesn't help (the base
class version kicks in instead) so the only way I can see is to redefine it
as "public" (using the "new" keyword) and then throwing a
"System.NotImplementedException" (also asserting in the debug version). This
is ugly IMO however so I'm hoping there's a cleaner way. Any advice would be
appreciated. Thanks.
If you don't want a client to be able to use a member of the base
class, you shouldn't derive from it.

You could make it virtual, override it, and add a deprecated attribute
to it - but it's a bit horrible. You *should* be able to use an
instance of a derived class as if it were an instance of the base
class.

Jon

Sep 27 '07 #2
On Sep 27, 2:21 pm, "MikeP" <no_spam@_nospam.comwrote:
>I wrote a replacement for the native .NET class "FileDialog" with my own
"FileOk" event (triggered when the user selects a file and clicks OK).
Let's
say I now want to create a derivative called "MyFileDialog" and replace
the
"FileOk" event with a new event called "MyFileOk". Users of this class
should therefore rely on the latter event and not "FileOk" from the base
class. Is it therefore possible to hide the base class' "FileOk" event so
that users can't invoke it. Redefining it as private doesn't help (the
base
class version kicks in instead) so the only way I can see is to redefine
it
as "public" (using the "new" keyword) and then throwing a
"System.NotImplementedException" (also asserting in the debug version).
This
is ugly IMO however so I'm hoping there's a cleaner way. Any advice would
be
appreciated. Thanks.

If you don't want a client to be able to use a member of the base
class, you shouldn't derive from it.

You could make it virtual, override it, and add a deprecated attribute
to it - but it's a bit horrible. You *should* be able to use an
instance of a derived class as if it were an instance of the base
class.
Thanks for the feedback. Actually I agree with this in principle. However,
this was a very late change so I didn't want to have to start aggregating
the base class as a private member (as one possible solution), especially
for this one minor change. Note that in C++ you have more flexibility with
this issue. You can privately derive from a base class for instance and then
publicly expose only what you want. I find this approach somewhat ugly as
well however. In any case, I'll probably stick with my original idea until
the next release since I control all clients anyway (though I might add the
obsolete attribute you suggested). Anyway, thanks again.
Sep 27 '07 #3

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

Similar topics

0
by: Rutger Claes | last post by:
How do I stop the SAX parser from replacing entities such as &#xE3; and &#xA9;. When I use &gt; and a default_handler, the default_handler is called and I can just print the data. Entities as &#xA9;...
3
by: John Livermore | last post by:
From javascript in IE, I have a need to hijack the onclick event for an element and replace it dynamically with my own. I have tried the following... control.onclick = 'myHandler();'; but...
2
by: Prashanth | last post by:
Hi, The application we are developing will be used worldwide by various individuals and organizations . As part of the security restrictions , some of the organization will disable client side...
1
by: seanmayhew | last post by:
Im attempting to get the vaules for the second drop down on index changed of the first. This works fine. However rather than just replacing the values of the second drop down with the new values...
3
by: jens.buchta | last post by:
Hi! I'm using a DataGrid with a template column to display an Image inside of it. I'm hooking into its OnPrerender-Event to set the ImageURL-Property dynamically. Everything works just fine...
1
by: patelgaurav85 | last post by:
Hi, I want to convert xml in one format into another xml format shown below Input xml : <Name> <Name1> <Name11>Name11</Name11> <Name12>Name12</Name12>
4
by: anonymoushamster | last post by:
Whether it is a checkbox to be replcaed with and image or a textbox to be repalced with a dropdown, imfailing. One simple reason. I can add a new compoentn into the edit row ,I jsut cant...
12
by: Jens | last post by:
Hi everyone, I'm trying to build a simple dropdown menu for a website and i need to need a way to retrieve the top and left style attributes of an object. However it seems style attributes like...
6
by: Trooper | last post by:
Hi! I want when user type comma in textbox to automaticly replace in dot. In keypress event i have something like this: if (e.KeyChar == 44) { textBox1.Text =...
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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,...
0
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.