Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to not create an explicit EventHandler delegate in Visual Studio?

Visual Studio likes to be helpful when typing:

Event +=

by generating code like:

Event += new EventHandler(EventClassName_Event);

void EventClassName_Event(object sender, EventArgs e)
{
    throw new System.NotImplementedException();
}

Ideally I would like to remove the explicit delegate and add an explicit private. Like so:

Event += EventClassName_Event;

private void EventClassName_Event(object sender, EventArgs e)
{
    throw new System.NotImplementedException();
}

I've looked to see if there is a snippet, but found nothing. Any suggestions? I do have ReSharper installed if there is a way that it can do this.

like image 237
Todd White Avatar asked Nov 17 '25 21:11

Todd White


1 Answers

With Resharper if I type:

myObject.SomeEvent += 

then hit Ctrl-Shift-Space, I get the option to create a method or a delegate (or to use an existing method). I think this is what you want.

like image 110
cbp Avatar answered Nov 20 '25 11:11

cbp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!