File-scoped namespace enabled by default
Answered
When creating a new C# class, I would like to have file-scoped namespaced class by default (for proper C# language).
Is that possible in Rider?
Please sign in to leave a comment.
Hello,
If the project C# language version is >=10.0, the class will be created with file-scoped namespace by default.
Please ensure the setting `File | Settings | Editor | Code Style | C# | Syntax Style | Code body | Namespaces` is set to File-scoped.
The language version is set to 10.0 by default in projects that target .NET6. You can force your project to use the exact language version by editing the .csproj or via `Right-click on project in Solution Explorer | Properties | Application | Language version`.
Sample .csproj with a language version set:
Please let me know if it doesn't help or anything is unclear.
Have a nice day!
Thank you for the help, Dmitry.
I've just found I had a setting overwritten in .editorconfig:
I removed that setting and now it works fine. Thank you!
Hello,
I am happy to hear that I was able to help you.
Should you have any other questions or difficulties in the future, do not hesitate to contact support.
Have a nice day!