question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Request] When creating a C# file, use file-scoped namespace declaration if possible

See original GitHub issue

In C# 10 we can now use a new form of the namespace declaration to declare that all subsequent declarations are members of the declared namespace:

namespace MyNamespace;

Is this extension able to detect the version of C# being used and use this new syntax?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
nathan130200commented, Sep 16, 2021

up

Update

After i read this extension source code, i’ve noticed that we can modify templates just:

  • Creating an folder in %USERPROFILE%\.vs\.templates
  • Then put all templates like in Templates folder in this repository.
  • Then we can change to use scoped namespace.
  • Restart visual studio and works!

Example: image

Content of .cs.txt that extension will read:

namespace {namespace};

public class {itemname}
{
        $
}

Same also for .cs-interface.txt

4reactions
fl3ppcommented, Oct 22, 2021

I feel like this feature should have been documented somewhere on the readme. I’ve been using this extension for quite some time, and this would have come in handy more than once.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How can I use a file-scoped namespace declaration in ...
You have to set up your project's editorconfig to prefer File-scoped namespaces. Right click your project. Select "Add" → "New Item".
Read more >
File scoped namespaces - C# feature specifications
This feature specification describes file scoped namespaces, where the entire contents of a file are included in a namespace declared at the ...
Read more >
File-Scoped Namespace Declaration in C#
In this article, we will learn about File-Scoped Namespace Declaration in C#. Introduction. Maintaining clean and organized code is crucial ...
Read more >
Using File-Scoped Namespaces in .NET 6 | by Jamie Burns
The main limitation we have when using file-scoped namespace is that a file can only contain a single namespace declaration. This makes sense, ......
Read more >
How to set C# 10+ file scoped namespaces as default in ...
Tried this and I still get an error that my 'file scoped namespace' is not available in C# 7.3. Please use language version...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found