user3347346
user3347346

Reputation: 67

How I can know which using-directives are missed?

If a using-directive is missing, is it possible that visual studio says me which using-directives are missing?

And if it is, can I configure my Visual Studio to set automatically the missing using-directives?

Visual studio tells me in the error-list only that any using-directive is missed, but I want to know which is missed?

Upvotes: 3

Views: 255

Answers (2)

Emond
Emond

Reputation: 50682

Visual Studio cannot know what using directives are missing, it can only guess. The same type name can be present in multiple namespaces and assemblies.

When it guesses it will look for the type(s) you are using and search referenced assemblies for the type. (Tools such as Resharper can guess better/more)

If the editor shows a blue rectangle below the type:

obligatory hand drawn arrow

, put the cursor in the type name and hit Shift+Alt+F10 or Ctrl+. (the shortcut for View.ShowSmartTag ) and a popup will allow you to select from the guesses. Of course you can right-click the type and use the context menu's Resolve or try and click the blue rectangle (RSI risk).

If the assembly is not referenced you will need to set the reference first. This means that you need to find out what assembly contains the type that you want to use. If it is a type from the .NET Framework you can use the MSDN; on the page that contains the type it will show you what assembly and what namespace the type resides in.

For instance:

IEnumerable Interface

.NET Framework 4.5

Exposes the enumerator, which supports a simple iteration over a collection of a specified type. To browse the .NET Framework source code for this type, see the Reference Source.

Namespace: System.Collections.Generic

Assembly: mscorlib (in mscorlib.dll)

Upvotes: 6

Kurubaran
Kurubaran

Reputation: 8902

If an using-directive is missing, is it possible that visual studio says me which using-directives are missed?

No


can I configure my visual studio to set automatically the missing using-directives?

No


Visual studio tells me in the error-list only that any using-directive is missed, but I want to know which is missed?

There are cases that required assembly reference is already exist under project reference but the using statement might be missing in the class. This is easy because you can spot the line where the build error appears and right click on the class and go to resolve and select the relevant using statement.

There might be cases where you might not have the required assembly reference added to the project(specially when you copy paste the code from somewhere else). first of all you will need to find out which .NET assembly reference needs to be added. search for the .net class name in MSDN relevant page will contain information of the .NET assembly where the class resides, Add particular assembly reference then follow the first step given above.

Upvotes: 0

Related Questions