E
Eric Newton
VB's more declarative nature of handling events is golden. I'm hoping C#
will acquire this type of deal, in addition to the anonymous delegates.
could do same as vb (actually would be easier to parse then vb due to
braces) whereas you look for Handles keyword after method sig, but before
opening brace of the method.
compiler would implicitly build event handling code for all typed
constructions, ie, any variables instances constructed via "new" operator,
compiler would follow with <instanceName>.<event> += new
<eventHandlerType>(<methodNameOfHandler>)
Seems like the algo could work like this
if "Handles" is found between method signature and first opening brace,
follow rules for dereferencing a simple expression of a type, followed by an
event name.
if expression is valid then
build implied code event handler creation for all found "new" operators
of the class
end if
c#:
private void Button_Click(object sender,EventArgs e) handles Button1.Click,
Button2.Click, Button3.Click
{
}
protected Button Button1;
private void InitializeComponent()
{
Button1 = new Button();
// implicit compiler event handling addition
Button1.Click += new EventHandler(Button1_Click); // statement is
implicit compiler addition
Button1.Text = "Button1";
// (finish building button1's properties)
Button2 = new Button();
// implicit compiler event handling addition
Button2.Click += new EventHandler(Button_Click);//statement is implicit
compiler add
Button2.Text = "Button2";
}
will acquire this type of deal, in addition to the anonymous delegates.
could do same as vb (actually would be easier to parse then vb due to
braces) whereas you look for Handles keyword after method sig, but before
opening brace of the method.
compiler would implicitly build event handling code for all typed
constructions, ie, any variables instances constructed via "new" operator,
compiler would follow with <instanceName>.<event> += new
<eventHandlerType>(<methodNameOfHandler>)
Seems like the algo could work like this
if "Handles" is found between method signature and first opening brace,
follow rules for dereferencing a simple expression of a type, followed by an
event name.
if expression is valid then
build implied code event handler creation for all found "new" operators
of the class
end if
c#:
private void Button_Click(object sender,EventArgs e) handles Button1.Click,
Button2.Click, Button3.Click
{
}
protected Button Button1;
private void InitializeComponent()
{
Button1 = new Button();
// implicit compiler event handling addition
Button1.Click += new EventHandler(Button1_Click); // statement is
implicit compiler addition
Button1.Text = "Button1";
// (finish building button1's properties)
Button2 = new Button();
// implicit compiler event handling addition
Button2.Click += new EventHandler(Button_Click);//statement is implicit
compiler add
Button2.Text = "Button2";
}