473,398 Members | 2,212 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,398 software developers and data experts.

C#-APP Is there any way to "redefine" a class legally ?

Hi all,

Recently I started using C#, I have a question: Can we redefine a class legally in C# ?

For example:

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("testing");
}

When the user click the button, it shows up a message box

If one day I want to log this action temporary, or prevent all the MessageBox from showing up entirely in my application, how can I make it happen without modifying all the MessageBox.Show() in my code ?

I know that I could make a subclass from MessageBox , use override or New, but it is not what I want. I am looking for a language facility for changing the behavior of any class (any method) dynamically in my namespace.

For example, I imagine that there is a keyword, let say, "OnEvent"

So that I can write some magic code like this:

OnEvent MessageBox Show( )
{
myClass.log( );
this.Show( );
}

after that, whenever I call Show() method from MessageBox class, the method actually got "hijacked" and under my control.

Any advice or comment is also welcomed.

Jeff
Apr 9 '08 #1
2 1558
Plater
7,872 Expert 4TB
I want to say the latest versions of .NET (3.0 and greater) have limited implimentation of this kind of thing, but I don't have .NET3.0 and couldn't test it.
As an in general I would say that no (unless you can find some sneaky Win32 API to do it) there is not really any good .net way to do it.

Which is why I start out all my project with creating a special function that I call from everywhere. Then inside that function I can dictate if I want it to log or show a messagebox or anything else. Abstracting out the IO is not a bad thing to do.
Apr 9 '08 #2
r035198x
13,262 8TB
Have a look at the Command pattern.
Apr 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: John J. Lee | last post by:
I'm trying to change a base class of a big class hierarchy. The hierarchy in question is 4DOM (from PyXML). 4DOM has an FtNode class that defines __getattr__ and __setattr__ that I need to...
5
by: Ulf Rimkus | last post by:
Hallo! Now I've tried out for quite a long time how to access the -operator from a base class. But I cannot find out how to do this. Well, it's an example from "Think in C++". So, I guess I...
6
by: eselk | last post by:
If I have: class A { public: class some_base_class **Obj; }; And I would like to redefine "Obj" in a class derived from class A, something like this maybe:
4
by: ABC | last post by:
I want define a base class as: class abc { class cde { } } when I inhert abc class,
4
by: Fedor Semenov | last post by:
How can I call a base class' constructor from a derived class. Suppose I have: class Button // Base class { public: Button(void) { // Register classes, create the button, etc. } };
25
by: paytam | last post by:
hi all I want to redefine a function getchar() in header stdio.h ,but I don't know what should I do.
11
by: food4uk | last post by:
Dear all : I am not good at programming, please give a hand. My data structure is very similar as an array. I actually can use the std::vector as container to organize my data objects. However,...
2
by: ERingmae | last post by:
Hi, The environment is .NET 2.0, the language is C# and the problem is reading XSD file with xs:redefine section correctly to a XMLDataDocument.DataSet. What I am trying to do: I am trying...
10
by: Amber | last post by:
For example if anywhere defined MyChar as typedef char MyChar; Now I want to redefine MyChar as wchar_t, how can I do this?
16
by: Stefano Sabatini | last post by:
Hi all, I'm facing this design problem. I have a table which defines the behaviour of an Object in a given state according to the type of event it is receiving. So for each couple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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.