开发者

How to autocomplete a delegate in Visual Studio

How do you autocomplete a method signature based on a delegate? Or atleast get some help from intellisense in completing the method signature.

Some method has a delegate as one of its parameters, so I have to create the method, call me lazy but it's quite painful to copy paste the method signature from MSDN.

I recall that when you specify an event handler, Visual Studio has an autocomplete feature for you (by hitting tab), but I wonder if th开发者_高级运维is is possible for other kind of delegates.


It is possible - just type the name of the new method where the delegate parameter is expected, press Ctrl+. (quick actions) and choose "Generate method...".

For example, you can do Shell.Current.Navigated += GetDelegate;, Ctrl+. (or click the quick actions icon (

How to autocomplete a delegate in Visual Studio

) and click "Generate Method". In this case, we'd get the following method generated:

private void GetDelegate(object sender, ShellNavigatedEventArgs e)
{
    throw new NotImplementedException();
}

Then just copy the signature from there and delete the generated method:

Shell.Current.Navigated += (object sender, ShellNavigatedEventArgs e) =>
{
};


You can't do this unless your are subscribing to an event. It can be a custom event of course.

But for other delegates not possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜