Namespaces and USING NAMESPACE

A NameSpace is a way to group related types into a coherent name hierarchy. For example the System::Windows::Forms namespace groups a lot of types related to Forms and Controls. Inside a NameSpace every Type name has to be unique.

A NameSpace also helps Programmers to avoid name collision. For example in the .NET Framework there are several classes named Control, but because these classes are contained in different NameSpaces there are not name collisions.

For example, the Checkbox type contained in the System::Windows::Forms NameSpace is referenced from VFPCompiler for .NET using its FullName: System::Windows::Forms::CheckBox.

VFPCompiler for .NET exposes namespaces extensions in several ways.

Declaring namespaces

To define a namespace

DEFINE NAMESPACE OuterName::MiddleName::InnerName

<types as classes, enums, structs are specified here>
DEFINE CLASS MyClass
ENDDEFINE

ENDDEFINE

Using classes inside namespaces

From outside the namespace to reference a class contained there you could use this syntax:

OuterName::MiddleName::InnerName::MyClass

And that is a really long name. In order to avoid having to write over and over the long name when you are going to use several types from that namespace, some syntax sugar is included:

USING NAMESPACE OuterName::MiddleName::InnerName

So instead of writing as:

TLOCAL Myvar as OuterName::MiddleName::InnerName::MyClass

You write:

TLOCAL MyVar as MyClass
You can also use a namespace using an ALIAS instead .
USING NAMESPACE System::IO::Compression FROM System AS MyCompression
TLOCAL oStream as MyCompression::GZipStream

That way you can use your own prefix to reference the types inside the namespace. This is useful when USING a namespace that contains some classes with names used in some other imported namespaces, or when USING a namespace would lead to Class NAME clash between different classes (in different namespaces) with the same name.