How can I change the default namespace used when you create a new class in Visual Studio?
Background: My solution has a project MyCompany.MyProject.Domain in which I have a folder "Model Base (Linq)" with a subfolder "Extensions" where I keep all partial class extensions.
MyCompany.MyProject.Domain + Model Base (Linq) + Extensions - Order.cs - Trace.cs
When I create a new .cs file in there, the namespace gets set to MyCompany.MyProject.Domain.Model_Base\_\_Linq\_\_.Extensions, I only want it to be MyCompany.MyProject.Domain.Model though.
How can I change this default behavior?
Just right click on the name you want to change (this could be namespace or whatever else) and select Refactor->Rename... Enter new name, leave location as [Global Namespace], check preview if you want and you're done!
If you are adding a new class in your code then you may need to add the correspondence namespaces. To do it, you may either manually type the Using Namespace or you just right click on the class name and select Resolve > Namespace. But using “Ctrl+.” you can automatically add the namespace in your code.
There are 4 schools of thought here:
I tend to use the 4th; it is quicker than editing, and less hassle than changing the templates
To change the default namespace:
Right click on the project, go to properties and under the 'Application' tab there is a 'Default namespace' field.
Note that this doesn't answer your exact question though, it depends on your folder. You basically you need to rename that folder to 'Model'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With