Declaring events and event handlers using CodeRush
With the help of CodeRush we can declare everything starting from undeclared local variables and members to undeclared objects like classes and structures. Here, we will take a look at the code declaration providers for declaring events and event handlers:
- Declare Event
- Declare Event Handler
The Declare Event code provider creates an event for an undeclared event reference, e.g:
If the Click event is not yet declared, you can apply the Declare Event code provider for the event reference:
The code provider will determine the resulting delegate type automatically:
As a complementary addition, there is another code provider which allows you to declare event handlers. The Declare Event Handler code provider is available on the reference to an undeclared event handler, e.g.:
The Timer object in this sample takes a single argument of the System.Threading.TimerCallBack type that represents a callback method to be executed. Applying the Declare Event Handler will generate the corresponding method with the signature of the TimerCallBack delegate: