Namespaces

The program structure in the Fore.NET language is organized using namespaces.

Compilation Units

A compilation unit determines the overall structure of a source program text file. A compilation unit consists of the following blocks (in the specified order): zero or more directives Imports, then zero or more global attributes, followed by zero or more namespace member declarations.

compilation-unit:

imports-directivesopt  global-attributesopt    namespace-member-declarationsopt

A Fore.NET program consists of one or more compilation units, each contained in a separate file of the source text. When a program is compiled, all of the compilation units are processed together. Thus, compilation units can depend on each other, possibly in a circular fashion.

The Imports directives of a compilation unit affect only the global attributes and namespace member declarations of that compilation unit, but have no effect on other compilation units.

Global attributes permit applying attributes to a compiled assembly.

The namespace member declarations of each compilation unit of a program contribute members to a single declaration space named a global namespace.

Imports Directive

The Imports directives facilitate the use of namespaces and types determined in other namespaces and affect the name resolution process during compilation.

The Imports directive imports types contained in a namespace to an immediately containing this directive compilation unit or another namespace body that enables the use of unqualified identifiers when referring to types.

imports-directives:

imports-directive

imports-directives  imports-directive

imports-directive:

Imports   namespace-name   ;

The Imports directive imports types contained in the specified namespace, but not the namespaces nested in this namespace. When an imported namespace contains a member with the same name as a name declared within the current compilation unit or namespace body, the locally declared name has priority over the imported one.

Namespace Declarations

A namespace declaration consists of the Namespace keyword, followed by a namespace name and body, ended with the keyword sequence End Namespace.

namespace-declaration:

Namespace   namespace-identifier  namespace-body  End Namespace namespace-identifieropt   ;

namespace-identifier:

qualified-identifier

qualified-identifier:

identifier

qualified-identifier   .   identifier

namespace-body:

imports-directivesopt   namespace-member-declarationsopt

A namespace declaration may occur as a top level declaration in a compilation unit or as a member declaration within another namespace. When a namespace is declared at a top level in a compilation unit, this namespace becomes a member of the global namespace. When a namespace is declared within another namespace, the inner namespace becomes a member of the outer namespace. In either case, the name of a namespace must be unique within the containing namespace.

Namespaces are implicitly public and the declaration of a namespace cannot include any access modifiers.

Optional Imports directives in a namespace body import names of other namespaces and types, allowing them to be referenced directly instead of through qualified identifiers.

Namespaces are open-ended, and two namespace declarations with the same fully qualified name contribute to the same declaration space.

Namespace Member Declarations

A namespace member declaration can be either a type declaration, a namespace declaration, or a global members declaration.

namespace-member-declarations:

namespace-member-declaration

namespace-member-declarations   namespace-member-declaration

namespace-member-declaration:

namespace-declaration

type-declaration

globals-declaration

Type Declarations

A type declaration is a class declaration, a structure declaration, an interface declaration, an enumeration declaration, or a delegate declaration.

type-declaration:

class-declaration

struct-declaration

interface-declaration

enum-declaration

delegate-declaration

A type can be declared either on a top level in a compilation unit, or as a member declaration within a namespace, a class, or a structure.

When a type declaration for a type T occurs as a top-level declaration in a compilation unit, its fully qualified name is simply T. When a type declaration occurs within a namespace, class or structure, its fully qualified name is N.T, where N is the full name of the containing namespace, class or structure. A type declared within a class or structure is named a nested type.  The permitted access modifiers for a type declaration depend on the context, in which the declaration takes place:

Global Members Declarations

The Fore.NET language supports declaration of global constants, variables and methods to ensure backward compatibility with the Fore language. It is highly recommended not to use global declarations in a newly started code, as the support of such language constructions is going to be stopped in the future.

globals-declaration:

global-constant-declaration

global-field-declaration

global-member-declaration

global-constant-declaration:

attributesopt  global-declaration-modifiersopt   Const   identifier   =   constant-expression   ;

global-field-declaration:

global-declaration-modifiersopt   Var   identifier   :   type   variable-initializeropt   ;

global-method-declaration:

global-sub-declaration

global-function-declaration

global-sub-declaration:

attributesopt   global-declaration-modifiersopt

Sub   member-name (  formal-parameter-listopt  ) ;   method-localsopt   

Begin   method-body   End Sub   member-nameopt   ;

global-function-declaration:

attributesopt   global-declaration-modifiersopt

Function   member-name (  formal-parameter-listopt )  :   return-type   ;   method-localsopt

Begin   method-body   End Function   member-nameopt   ;

global-declaration -modifiers:

Public

Friend

Declaration of global members of a namespace results in declaration of a special system class __Globals in this namespace and declaration of this class members corresponding to global members declarations:

Global declarations in a namespace are used in the simple name, member access and overloaded names resolution process.

Example

Imports System;
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Ui;

[Assembly(AssemblyTitle("Test application"))]
[Assembly(AssemblyCompanyAttribute("Any Company"))]
[Assembly(AssemblyVersion("1.0.0.0"))]

Namespace UserApplication
    Var
        s: string;
        i: integer;
    Const
        e = 0.0001;
    //Declaration of types and type members
    //organizing the code of the custom application
End Namespace;

See also:

Description and Syntax Rules