Importing nested namespaces automatically in C#
C# is not Java.
A using
directive is used so you don't have to type in the fully qualified name of a type. It also helps with disambiguating type names (using aliases for instance).
In the case of Console
, for example, you don't need to type System.Console
.
It is important to understand the difference between a namespace and an assembly - a namespace is a logical grouping of types. An assembly is a physical grouping of types. Namespaces can span assemblies.
When you reference an assembly (this is more like importing a package in Java), you gain access to all of the public types in it. In order to use a type you need to uniquely identify it. This is done through the namespace - the using
directive simply means you don't have to type the fully qualified name of the type.
Nested Namespaces in C#
One way that would probably work is to using a global find and replace. What your actually trying to do is to rename two namespaces into one, and it's not going to let you.
Namespace being automatically imported
What namespace is your ASP .Net code in?
It's probably inside of HRCommon.
If you write code in a nested namespace, it will automatically import all parent namespaces (eg, code in System.Windows.Forms
doesn't need to import System.Windows
and System
)
To prevent this, move either the library or the ASP .Net project to a different namespace.
Alternatively, you might not have namespace
statements in the library.
The Default Namespace option in VS is only used to generate the namespace
block in new C# source. EDIT: To clarify, the Default Namespace setting is not used by the compiler at all. It's only used by the Visual Studio to automatically insert namespace
blocks in new source files.
Check the source files in the library and make sure that all of the classes are defined inside of the namespace HRCommon
.
For example:
namespace HRCommon {
public class MyClass {
//...
}
}
Not able to import namespaces automatically in Visual Studio
If you have a namespace in a different DLL in your project, you first need to right-click references and select "add reference" and then checkmark the dll.
After doing this, CTRL+DOT will work :)
If it is a reference to an external package, such as NuGet, you can right-click the solution file and choose "Restore Nuget Packages"
Related Topics
Async/Await Different Thread Id
What Is the Correct Way to Read a Serial Port Using .Net Framework
I Need a Fast Runtime Expression Parser
Calculated Column in Ef Code First
App.Config for a Class Library
Does a Locked Object Stay Locked If an Exception Occurs Inside It
Nice & Universal Way to Convert List of Items to Tree
How to Transfer Authentication from Webbrowser to Webrequest
Using the C# Dispatcher in Wpf Applications
How to Get Urls of Open Pages from Chrome and Firefox
How to Enumerate Through a Jobject
What Is the Use of the Arraysegment<T> Class
Use of SQLparameter in SQL Like Clause Not Working
How to Seed an Admin User in Ef Core 2.1.0
Why Does Wcf Return Myobject[] Instead of List<T> Like I Was Expecting