C# Formatting Style - Braces Layout if statement
I guess since newest version of ReSharper (I use the latest EAP) for if statements always braces are removed if there is only a single line inside braces. I cannot figure out how to configure to get _always_ braces .
Example:
if (basevalue != null)
{
if (!((SmartDateEditExtendet) d).IsNullable)
{
((SmartDateEditExtendet) d).SetEditValueInternal(FormatEditValue((DateTime) basevalue));
}
else if (basevalue != null && basevalue.ToString() != string.Empty)
{
((SmartDateEditExtendet) d).SetEditValueInternal(FormatEditValue((DateTime) basevalue));
}
}
will be reformated as:
if (basevalue != null)
if (!((SmartDateEditExtendet) d).IsNullable)
((SmartDateEditExtendet) d).SetEditValueInternal(FormatEditValue((DateTime) basevalue));
else if (basevalue != null && basevalue.ToString() != string.Empty)
((SmartDateEditExtendet) d).SetEditValueInternal(FormatEditValue((DateTime) basevalue));
Wo don't want this reformating. Ho can I set the Options to keep this braces?
Please sign in to leave a comment.
Found it! It's under Code Style *phew*
It seems that the "Enforce always" does not work correctly in 2017.3 EAP 7. I have enabled "Enforce always" in "if" statement yet the following line of code is not formatted:
if (source == null) return new Core.Entities.DeceaseInfo();
Expected formatting is:
if (source == null)
{
return new Core.Entities.DeceaseInfo();
}
When I add the curly braces myself and then reformat the code, the braces will not be removed so that's okay. But they are supposed to be added.
Hello Gabriel!
To apply Code Style settings please use ReSharper | Edit | Cleanup Code | Full Cleanup or ReSharper | Edit | Apply Code Style.
Here's some more detailed information on this matter - https://www.jetbrains.com/help/resharper/Braces_for_Single_Line_Statements.html
Thank you