Reputation: 393
In Visual Studion 2017 Pro, whenever I override a method in a C# child class, I type override
space, then use the first couple letters and IntelliSense to select the method I want to override.
This inserts the rest of the method signature and a call to the base method, but uses an expression body for the method (lambda):
public override string ToString() => base.ToString();
Instead of a block body (curly brackets):
public override string ToString()
{
return base.ToString();
}
This makes overriding methods tedious. I only override the method if I am going to change what the method does, which almost always requires it to be in a block body to be legible (especially if calling the base method).
Note: Some settings were defaulted by my organization when installing VS2017, that probably set this for single line methods, which the override method will always initially be.
Is there a setting in Visual Studio that controls this behavior?
Upvotes: 0
Views: 219
Reputation: 9704
The setting you're looking for can be found under the Code Style settings for C#.
You can navigate to the setting like so:
Tools > Options > Text Editor > C# > Code Style
You are then looking for the setting description 'Use expession body for methods'. It is likely to currently be 'When possible'
or 'When on single line'
, but changing this setting to 'Never'
should result in the desired behavior.
Upvotes: 4