CodeNamespaceImport 类

定义

表示指示要使用的命名空间的命名空间导入指令。

public ref class CodeNamespaceImport : System::CodeDom::CodeObject
public class CodeNamespaceImport : System.CodeDom.CodeObject
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeNamespaceImport : System.CodeDom.CodeObject
type CodeNamespaceImport = class
    inherit CodeObject
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeNamespaceImport = class
    inherit CodeObject
Public Class CodeNamespaceImport
Inherits CodeObject
继承
CodeNamespaceImport
属性

示例

以下示例代码演示如何使用导入CodeNamespaceImportCodeNamespaceImport命名空间:

// Declares a compile unit to contain a namespace.
CodeCompileUnit compileUnit = new CodeCompileUnit();

// Declares a namespace named TestNamespace.
CodeNamespace testNamespace = new CodeNamespace("TestNamespace");
// Adds the namespace to the namespace collection of the compile unit.
compileUnit.Namespaces.Add(testNamespace);

// Declares a namespace import of the System namespace.
CodeNamespaceImport import1 = new CodeNamespaceImport("System");
// Adds the namespace import to the namespace imports collection of the namespace.
testNamespace.Imports.Add(import1);

// A C# code generator produces the following source code for the preceeding example code:

//    namespace TestNamespace {
//        using System;
//
//  }
' Declares a compile unit to contain a namespace.
Dim compileUnit As New CodeCompileUnit()

' Declares a namespace named TestNamespace.
Dim testNamespace As New CodeNamespace("TestNamespace")
' Adds the namespace to the namespace collection of the compile unit.
compileUnit.Namespaces.Add(testNamespace)

' Declares a namespace import of the System namespace.
Dim import1 As New CodeNamespaceImport("System")
' Adds the namespace import to the namespace imports collection of the namespace.
testNamespace.Imports.Add(import1)

' A Visual Basic code generator produces the following source code for the preceeding example code:

'Option Strict Off
'Option Explicit On
'
'            '
'Namespace TestNamespace
'End Namespace

注解

CodeNamespaceImport 可用于表示命名空间导入指令。

在大多数语言中,命名空间导入指令会导致导入的命名空间中的类型可见性到引用导入命名空间中的类型的代码。

注释

使用完全限定的类型引用以避免潜在的歧义。

构造函数

名称 说明
CodeNamespaceImport()

初始化 CodeNamespaceImport 类的新实例。

CodeNamespaceImport(String)

使用指定的命名空间来导入类的新实例 CodeNamespaceImport

属性

名称 说明
LinePragma

获取或设置语句发生的行和文件。

Namespace

获取或设置要导入的命名空间。

UserData

获取当前对象的用户可定义数据。

(继承自 CodeObject)

方法

名称 说明
Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅