Can Visual Studio use a 'Block Body' when using 'Generate Method', but still prefer 'Expression Body' otherwise? (VS2019)

Viewed 272

I use 'Generate Method' a lot (when typing a missing method call, Visual Studio offers to generate it), but when the options are set to prefer an Expression Body, it generates an Expression Body like this:

private void Blah() => throw new NotImplementedException();

I then have to convert it to a block body because most methods aren't one line. Is there any way to get Visual Studio to generate block body methods but still suggest expression body methods?

1 Answers

I then have to convert it to a block body because most methods aren't one line. Is there any way to get Visual Studio to generate block body methods but still suggest expression body methods?

Solution

Please change this:

Tools-->Options-->Text Editor-->C#-->Code Style-->Expression Preferences-->

change Preference of Use expression body for methods to Never

enter image description here

Hope it could help you.

Related