Show/Hide Toolbars

XSharp

The -ns option explicitly specifies the default namespace for all types that do not have an explicit namespace in their name.

Syntax

-ns[: ]namespaceName

Arguments

namespaceName The name of the default namespace for all types declared in the application or class library.

Remarks

If The -ns option is not specified, then types that are not prefixed with a namespace and types that are not in a BEGIN NAMESPACE .. END NAMESPACE construct will be compiled as so-called global types.

 

The -ns option will work on the following types:

 

Classes

Interfaces

Structures

Vostructs

Delegates

 

Namespace names must follow the same rules for program identifiers: they must begin with an uppercase or lowercase letter or an underscore, followed by zero or more uppercase or lowercase letters, numbers or underscores. All other characters are illegal, and will raise a compile-time error.

 

The default namespace is used for any declared types that do not have an explicit namespace in their name.

To set this compiler option in the Visual Studio development environment:

 

1.Open the project's Properties page.

2.Click the General tab.

3.In the Application section, modify the Default Namespace property.

4.Click the Language tab

5.In the Namespaces section, modify the Prefix classes with Default Namespace property.

6.Click here to see the property page

Example

 

When the following code is compiled without -ns compiler option the following types will be produced:

 

Customer

Point

MyProject.Customer

MyProject.Data.Customer

 

CLASS Customer
.
.
END CLASS
 
STRUCT Point
.
.
END STRUCT
 
ENUM CustomerType
.
END ENUM
 
CLASS MyProject.Customer
.
.
END CLASS
 
 
BEGIN NAMESPACE MyProject.Data
CLASS Customer
.
.
END CLASS
END NAMESPACE
 

 

 

If you compile the same code with a -ns:MyNameSpace option the following types will be produced:

 

MyNameSpace.Customer

MyNameSpace.Point

MyProject.Customer

MyProject.Data.Customer