我可以自定义在Visual Studio自动事件处理程序生成? [英] Can I customize automatic event handler generation in Visual Studio?
问题描述
当您订阅在代码中一个事件时,Visual Studio将自动在 + =
完成的代码,并生成相应的事件处理程序:
When you subscribe to an event in code, Visual Studio automatically completes the code after +=
and generates the appropriate event handler:
button.Click += new EventHandler(button_Click);
// ↑_____auto generated code_____↑
注意如何明确创建委托实例:即使虽然方法组是隐式转换为自C#2代表,IDE行为仍然没有在VS2010改变。
Notice how it explicitly creates the delegate instance: even though method groups are implicitly convertible to delegates since C# 2, the IDE behavior still hasn't changed in VS2010.
所以我想知道,有没有办法产生这样的代码,而不是
So I'd like to know, is there a way to generate code like this instead?
button.Click += button_Click;
编辑结果
刚使事情每个人都清楚:上面的代码的不的一个设计文件(我不关心哪个语法,如果它是的情况下使用)。这是当你键入触发段 + =
事件名称,然后按<大骨节病>标签骨节病>
EDIT
just to make things clear to everyone: the code above is not in a designer file (I wouldn't care which syntax is used if it was the case). It's the snippet that is triggered when you type +=
after an event name and press TAB
EDIT2结果
我报这是一个的 Connect(连接)建议,你可以为它投票,如果你也想改变目前的行为
EDIT2
I reported this as a suggestion on Connect, you can vote for it if you also want the current behavior to be changed
推荐答案
的 Connect(连接)建议已被标记为固定的,所以新的行为应该是。包括在VS11的下一个公开版本
The suggestion on Connect has been marked as fixed, so the new behavior should be included in the next public build of VS11.
编辑:刚刚检查,这的确是包含在测试版
just checked, it is indeed included in the beta.
这篇关于我可以自定义在Visual Studio自动事件处理程序生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!