Is it possible to add a using declaration to a namespace globally?
For example, I want all of my classes under the "MyApp.Models" namespace to include the namespace System.Linq.Dynamic.
In asp.net you can do this for view by adding the namespace in the web.config. Is there a way to do this for class files as well?
No. It is not possible to add a global using
declaration to a C# project. You must specify the complete set of using
in each .cs file
It's not possible to do what you want with obvious functionality but you could create a template that you generate your classes from and do that by namespace, the templates could include the using and this would give you the desired effect.
You could do this with basic T4 templates or something like resharper also has this functionality.
However it is a bit pointless, lots of productivity tools will bring in the using statements you need given code you write, resharper and others do this, so it is not neccessary to have a template that does this as you may end up in each namespace not using the declaration then find yourself having to delete it !
Theres not really an issue with having using statements that are unused by the way its just messy.
Ooh just in case you aren't sure what t4 templating is here is a quick link
I don't believe this is possible out of the box, but you could certainly automate with a Visual Studio plugin or a plugin for a tool like Code Rush.
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