Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to alter the auto generated event handler code within visual studio?

I would like to be able to control the default code that's generated for event's when I use one of Visual Studio's automatically generated blocks. The current template is as follows:

void HandlerName(object sender, HandlerEventArgs e) {
    throw new NotImplementedException();
}

I would like to change this to the following:

private void HandlerName(object sender, HandlerEventArgs args) {
    throw new NotImplementedException();
}

Namely it's the args argument that I always change.

UPDATE: Further to this it is policy that we also include comments for private members here, thus another use-case for my requirement is to also generate the default comment.

UPDATE 2: I now retract the reasoning for wanting to rename e to args due to evidence of a non-standard naming convention, however I still would like to override the template if possible for explicit access modifier and default comments.

like image 647
Brett Ryan Avatar asked Jun 27 '11 02:06

Brett Ryan


People also ask

What is an event handler in Visual studio?

An event handler is the code you write to respond to an event. An event handler in Visual Basic is a Sub procedure. However, you do not normally call it the same way as other Sub procedures. Instead, you identify the procedure as a handler for the event.

How do you create event handlers with visual studio net?

From the Class Name drop-down list at the top of the Code Editor, select the object that you want to create an event handler for. From the Method Name drop-down list at the top of the Code Editor, select the event. Visual Studio creates the event handler and moves the insertion point to the newly created event handler.

What is event and event handler in vb net?

Clicking on a button, or entering some text in a text box, or clicking on a menu item, all are examples of events. An event is an action that calls a function or may cause another event. Event handlers are functions that tell how to respond to an event. VB.Net is an event-driven language.


1 Answers

I think the e comes from the delegate signature (delegate void HandlerEventHandler(object sender, HandlerEventArgs e)), so you can't change it without also changing the delegate signature...

like image 189
Thomas Levesque Avatar answered Sep 26 '22 06:09

Thomas Levesque