Namespaces

Namespaces organize functions and types into stable compile-time symbol hierarchies with no runtime representation.

File-scoped namespaces

A dotted namespace name is declared once at the beginning of a file and applies to every declaration in that file.

namespace Xenon.Math;

public double Square(double value)
{
    return value * value;
}

The full symbol name of this function is Xenon.Math.Square.

One namespace, multiple files

Several .xe files may contribute declarations to the same namespace. Folder layout and namespace hierarchy remain independent.

vector.xe
namespace Xenon.Math;

struct Vector2
{
    public float X;
    public float Y;
}
length.xe
namespace Xenon.Math;

public float LengthSquared(Vector2 value)
{
    return value.X * value.X + value.Y * value.Y;
}

Imports and qualified names

A using directive placed before the namespace declaration brings public symbols from another namespace into scope.

using Xenon.Math;

namespace Example;

float Measure(Vector2 value)
{
    return LengthSquared(value);
}

Qualified calls such as Xenon.Math.LengthSquared(value) express the same relationship directly.

Namespace aliases

An alias gives a shorter name to a namespace without importing all of its members as unqualified names. Use the alias as the first part of a qualified type or function name.

using Math = Xenon.Math;

namespace Example;

Math.Vector2 Create(float x, float y)
{
    Math.Vector2 value = Math.Vector2 { x, y };
    float length = Math.LengthSquared(value);
    return value;
}

Type aliases

An alias may also name one specific type. The alias can then be used anywhere that type name is expected.

using Vec2 = Xenon.Math.Vector2;

namespace Example;

Vec2 origin = Vec2 { 0.0f, 0.0f };

Type aliases are useful when two imported namespaces expose types with the same short name:

using PhysicsBody = Physics.Body;
using RenderBody = Graphics.Body;
File-local names

Both regular using directives and aliases affect only the file that declares them. An alias does not create a new type or namespace, change the target symbol, or bypass its visibility.