Mark Broadbent said:
Hahaha. Nice one!
So we have ...
Normal = MessageBox.Show(...)
= 15 char
Your = X + Y
where
X = chars needed to declare instance of your class OR chars of class -if
your method is static
Y = your function name
(oh and don't forget add a reference to your dll!)
You're making a huge stretch here. For a start the class is already declared
with other common function in it (obviously you have such a class, right?).
The class is not in a dll and it is only declared once anyway. Have a look
at these couple of examples to see the big difference
MessageBox.Show("Text", "Caption", MessageBoxButtons.OK,
MessageBoxIcon.Information);
becomes
GT.MsgBox("Text")
if(MessageBox.Show("Save Changes?", "Caption",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1) == DialogResult.Yes)
becomes
if(GT.MsgBoxSaveChanges() == DialogResult.Yes)
I bet yours is bigger than the normal syntax. MessageBox.Show is
overloaded so those extra params are not necessary.
Actually they are. You really need to have an icon on the messagebox so you
have to have at least the first 4 params.
I know where you are coming from though, especially if you are using
particular default parameters for the same look and feel of your
messagebox, but reinventing the wheel JUST to save some typing is in this
instance a very bad idea.
Total rubbish. How can this be a very bad idea? What possible side effects
could there be?
If you took this to it's logical conclusion you would be eventually doing
this for nearly everything in the framework.
Not really. If you think about it there are only a few places where you'd
use this sort of thing, the other one I use it for is adding params to a
command object.
I can think of a couple of reasons to do this kind of thing, but saving
typing aint one of them.
I don't see anything wrong with saving typing, although it also makes the
code more readable and reduces repeat code. If the caption of the MessageBox
is the same throughout the app why should I specify it in hundreds of
locations. (My app has 300 forms each of which would show at *least* one
messagebox).
What I would do instead is create a simple VS macro OR use one of the
productivity editor add-ins to VS so that you could (at the press of a
couple of keys) insert the base code of your messagebox statement.>
This sort of thing leads to lots of repeat code.
Michael