VS.NET suggestion - anonymous delegate auto-complete
Preface:
Let’s say that you have Button control named myBtn and you want to handle its Click event:
myBtn.Click += new EventHandler(myBtn_Click);
static
void myBtn_Click(object sender, EventArgs e) {// do something
}
Now, raise your hand if you ever attached the event handler to the event manually, meaning you wrote “new EventHandler(myBtn_Click);” or even specified the method signature “void myBtn_Click(object sender, EventArgs e)”.
I don’t know about you, but the way I work is by simply writing “myBtn.Click +=” and this magic yellow thingi appears:
TAB-ing again will generate the method stub and I’m good to go.
Doing this yellow magic on delegates parameters:
We all(?) worked with List<T>. This nice class has some nice methods like ForEach, FindAll, Find etc which get delegate(Action<T>\Predicate<T>) as parameter. for example:
List<int> numbers = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
// Print the numbers via ForEach method
numbers.ForEach(delegate(int i) {
Console.Write(i);
});
Would it be great if you can write something like:
numbers.ForEach(
And the yellow thingi will popup and by clicking TAB this code will be generated:
numbers.ForEach(delegate(int i) {
//TODO
});
This means that this IDE feature should check the type of the delegate – the number and type (even generic type!) of parameters and the return type. This will prevent us from looking at MSDN or “Go To Definition” while working with delegates which are sent as parameters.
Time for you to make a difference:
what say you ? can this save you some time ? If so – leave a comment, I’ll do my best to implement it or to forward this request to MS folks (as ladybug).