Home > Code Generation > Declaring events and event handlers using CodeRush

Declaring events and event handlers using CodeRush

September 21st, 2012

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:

CodeRush Declare Event Code Sample

If the Click event is not yet declared, you can apply the Declare Event code provider for the event reference:

CodeRush Declare Event Preview

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.:

CodeRush Declare Event Handler Preview

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:

CodeRush Declare Event Handler Result

—–
Products: CodeRush Pro
Versions: 12.1 and up
VS IDEs: 2008 and up
Updated: Sep/21/2012
ID: C188

Similar Posts: