0

Subscribing to event is easy: type +=, hit Tab:

enter image description here

But is there an easy way to create event handler method when there is no += ? To example when event is a method parameters:

enter image description here

My current approach is very inefficient:

  • Look at method signature (using F12 - go to definition);
  • Copy type of EventHandler<T>;
  • manually type and paste to create event handler: void foo(object sender,Ctrl+V args).

Do I miss something? Is there a quicker way to create foo?

P.S.: I am talking about event handlers, but this question may be extended to creating delegate callbacks too.

1 Answer 1

2

Type the name of the method that you want to generate (as if it already existed), then put your cursor over the name and press Ctrl+., and select "Generate method ...":

Screenshot showing refactoring to "Generate method"

EventHandler and EventHandler<T> are just a types of delegate -- they're no different to e.g. Func or Action, other than the way in which they're normally used.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.