CodeNamespace 类

定义

表示命名空间声明。Represents a namespace declaration.

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

示例

下面的示例代码演示CodeNamespace如何使用来声明命名空间。The following example code demonstrates use of a CodeNamespace to declare a namespace.

CodeCompileUnit^ compileUnit = gcnew CodeCompileUnit;
CodeNamespace^ namespace1 = gcnew CodeNamespace( "TestNamespace" );
compileUnit->Namespaces->Add( namespace1 );

// A C# code generator produces the following source code for the preceeding example code:
//     namespace TestNamespace {    
//     }
CodeCompileUnit compileUnit = new CodeCompileUnit();
CodeNamespace namespace1 = new CodeNamespace("TestNamespace");
compileUnit.Namespaces.Add( namespace1 );

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

//     namespace TestNamespace {    
//     }

Dim compileUnit As New CodeCompileUnit()
Dim namespace1 As New CodeNamespace("TestNamespace")
compileUnit.Namespaces.Add(namespace1)

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

'     Namespace TestNamespace
'     End Namespace

注解

CodeNamespace可用于表示命名空间声明。CodeNamespace can be used to represent a namespace declaration.

Name属性指定命名空间的名称。The Name property specifies the name of the namespace. Imports属性包含命名空间的命名空间导入指令。The Imports property contains the namespace import directives for the namespace. Types属性包含命名空间的类型声明。The Types property contains the type declarations for the namespace. Comments属性包含应用于命名空间级别的注释。The Comments property contains the comments that apply at the namespace level.

在某些语言中,命名空间可充当类型声明的容器;如果类型名称之间没有冲突,同一命名空间中的所有类型都是可访问的,而无需使用完全限定的类型引用。In some languages, a namespace can function as a container for type declarations; all types in the same namespace are accessible without using fully-qualified type references, if the there is no conflict between type names.

备注

使用完全限定的类型引用,以避免潜在的歧义。Use fully qualified type references to avoid potential ambiguity.

构造函数

CodeNamespace()

初始化 CodeNamespace 类的新实例。Initializes a new instance of the CodeNamespace class.

CodeNamespace(String)

使用指定的名称初始化 CodeNamespace 类的新实例。Initializes a new instance of the CodeNamespace class using the specified name.

属性

Comments

获取命名空间的注释。Gets the comments for the namespace.

Imports

获取命名空间使用的命名空间导入指令集合。Gets the collection of namespace import directives used by the namespace.

Name

获取或设置命名空间的名称。Gets or sets the name of the namespace.

Types

获取命名空间包含的类型集合。Gets the collection of types that the namespace contains.

UserData

获取当前对象的用户可定义数据。Gets the user-definable data for the current object.

(继承自 CodeObject)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

事件

PopulateComments

在首次访问 Comments 集合时将激发的事件。An event that will be raised the first time the Comments collection is accessed.

PopulateImports

在首次访问 Imports 集合时将激发的事件。An event that will be raised the first time the Imports collection is accessed.

PopulateTypes

在首次访问 Types 集合时将激发的事件。An event that will be raised the first time the Types collection is accessed.

适用于