Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

c# - Can I customize automatic event handler generation in 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_____↑

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
I reported this as a suggestion on Connect, you can vote for it if you also want the current behavior to be changed

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The suggestion on Connect has been marked as fixed, so the new behavior should be included in the next public build of VS11.

EDIT: just checked, it is indeed included in the beta.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...