On this page

22. Extensions

22.1 Declarations and receiver

CS-EXTENSION-001. An extension Type ... end extension declaration is top-level, alongside ordinary type declarations. It supplies extension actions without modifying the original type or introducing a special runtime. Call sites use ordinary member syntax.

extension Global.System.DateOnly
    public action IsBusinessDay()
        returns Boolean
        return self.DayOfWeek <> Global.System.DayOfWeek.Saturday and
            self.DayOfWeek <> Global.System.DayOfWeek.Sunday
    end action
end extension

self denotes the current receiver both inside an extension and inside an ordinary class. Generic targets use ordinary generic syntax and constraints. Extension properties are not part of the core extension surface.

22.2 Binding and .NET relation

CS-EXTENSION-002. Applicable visibility, imports, overload resolution, generic inference and assignability are ordinary binding rules. An extension cannot grant access to otherwise inaccessible members of its receiver. Ambiguous candidates are errors, not reference-order selection. Extension declaration does not add a CLR member to the target type.

Representative reference C# lowering:

public static class DateOnlyExtensions
{
    public static bool IsBusinessDay(this DateOnly self)
    {
        return self.DayOfWeek != DayOfWeek.Saturday
            && self.DayOfWeek != DayOfWeek.Sunday;
    }
}

The generated static containing type is an implementation detail. A receiver obtained through an effectful expression is not duplicated to perform extension dispatch.


Specification contents · Previous: 21. Attributes and documentation metadata · Next: 23. Features