Nesting "using" statements resolves in error

As you can see from the screenshots below, nesting "using" statements gives a syntax error unless each using statement is wrapped in a curly brace.

This behavior is completely supported and works in Visual Studio.

If you were to disable the warnings, the file gets formatted with everything nested, making it not ideal and hard to read.

This is the expected behavior

When using Resharper with Visual Studio, it behaves the same way.

The reason why nested "using" need to be supported is for popular libraries like Serilog requiring this type of structure to add more context to logs.

Thanks!

1 comment
Comment actions Permalink

Hello,

 

Please change the following settings to avoid the specified behavior:

  • disable Settings | Editor | Inspection Settings | Inspection Severity | C# | Formatting | Incorrect Indent | Around child statement  (or either disable Settings | Editor | Code Style | C# | Tabs, Indents, Alignment | Indent nested "using" statements)
  • change Settings | Editor | Code Style | C# | Syntax Style | Braces | in "using" statement to "Do not enforce".

Please let me know if you have any more questions.

Thank you.

0

Please sign in to leave a comment.