开发者

VB.NET 2K8: How to make all imports visible within a class?

开发者 https://www.devze.com 2023-02-13 12:55 出处:网络
Generally speaking, a common VB.NET class should look like the following: Public Class MyClassName End Class

Generally speaking, a common VB.NET class should look like the following:

Public Class MyClassName

End Class

Besides, I have already seen, if I remember correctly, all of the import statements visible just like in C#:

Imports System
Imports System.Data
Imports System.Linq

Public Class MyClassName

End Class

How to make these default imports visible by default in VB.NET using Visual Studio 2008?

Is there some setting or the like in the options I shall set?开发者_如何学JAVA

Thanks! =)


Good question. The VB.NET Language spec only mentions "implicit imports" without giving an authoritative list. I can reverse-engineer it from the command line as shown in the output window, VS2008 and VS2010 uses this /Imports command line option:

  • Microsoft.VisualBasic,
  • System,
  • System.Collections,
  • System.Collections.Generic,
  • System.Data,
  • System.Diagnostics,
  • System.Linq,
  • System.Xml.Linq

MSBuild sets these in Microsoft.VisualBasic.targets from the Import variable. Which is set in the .vbproj file:

  <ItemGroup>
    <Import Include="Microsoft.VisualBasic" />
    <Import Include="System" />
    <Import Include="System.Collections" />
    <Import Include="System.Collections.Generic" />
    <Import Include="System.Data" />
    <Import Include="System.Diagnostics" />
    <Import Include="System.Linq" />
    <Import Include="System.Xml.Linq" />
  </ItemGroup>

Altering the Project + Reference setting does alter this list but there's no obvious one-to-one correspondence since this screen changes assembly references, the <Import> build variable lists name spaces. I'll have to punt, this ultimately is determined by the project template.


Right click on the project in Visual Studio then go to Properties. On the "References" tab there is a list of imported namespaces at the bottom. Anything added there doesn't need to be imported for any file in the project.

So to see the ones that are defaulting, you can just look there. :)


I think you're thinking 'Imports xxlibnamexx'

And as far as I am aware, if they are not in the text source file, they may just be System related ones that are intrinsically imported.

0

精彩评论

暂无评论...
验证码 换一张
取 消