CodeNamespace Class
TOC
Collapse the table of content
Expand the table of content

CodeNamespace Class

 

Represents a namespace declaration.

Namespace:   System.CodeDom
Assembly:  System (in System.dll)

System.Object
  System.CodeDom.CodeObject
    System.CodeDom.CodeNamespace

[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class CodeNamespace : CodeObject

NameDescription
System_CAPS_pubmethodCodeNamespace()

Initializes a new instance of the CodeNamespace class.

System_CAPS_pubmethodCodeNamespace(String)

Initializes a new instance of the CodeNamespace class using the specified name.

NameDescription
System_CAPS_pubpropertyComments

Gets the comments for the namespace.

System_CAPS_pubpropertyImports

Gets the collection of namespace import directives used by the namespace.

System_CAPS_pubpropertyName

Gets or sets the name of the namespace.

System_CAPS_pubpropertyTypes

Gets the collection of types that the namespace contains.

System_CAPS_pubpropertyUserData

Gets the user-definable data for the current object.(Inherited from CodeObject.)

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubeventPopulateComments

An event that will be raised the first time the Comments collection is accessed.

System_CAPS_pubeventPopulateImports

An event that will be raised the first time the Imports collection is accessed.

System_CAPS_pubeventPopulateTypes

An event that will be raised the first time the Types collection is accessed.

CodeNamespace can be used to represent a namespace declaration.

The Name property specifies the name of the namespace. The Imports property contains the namespace import directives for the namespace. The Types property contains the type declarations for the namespace. 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.

System_CAPS_noteNote

Use fully qualified type references to avoid potential ambiguity.

The following example code demonstrates use of a CodeNamespace to declare a namespace.

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 {    
//     }

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft