Implemented for the next release as a general language feature, not something specific to Colour.
https://feedback.objo.dev/feature/1282
When the compiler knows the expected type, a leading-dot expression can now resolve either:
- An enum member.
- An accessible shared property that returns the expected type or a compatible subtype.
For example:
g.DrawingColour = .Red
is equivalent to:
g.DrawingColour = Colour.Red
The same syntax works with user-defined classes:
Class Theme
Shared Property Light As Theme
Shared Property Dark As Theme
End Class
Var theme As Theme = .Dark
Here, .Dark is equivalent to Theme.Dark.
Existing enum shorthand continues to work:
Enum Direction
North
East
South
West
End Enum
Var direction As Direction = .North
Contextual dot shorthand is supported wherever the expected type is unambiguous, including:
- Typed variable, constant, and property assignments.
- Method and constructor arguments.
- Return statements.
- Comparisons.
Select Case values.
- Property and parameter defaults.
- Typed array literals and indexed assignments.
For example:
Sub ApplyTheme(theme As Theme)
End Sub
Function DefaultTheme() As Theme
Return .Dark
End Function
ApplyTheme(.Light)
If theme = .Dark Then
Print("Dark theme selected")
End If
Studio autocomplete supports the same feature. Typing:
g.DrawingColour = .
will offer compatible shared Colour values such as .Red and .Transparent. Likewise, typing:
Var theme As Theme = .
will offer values such as .Light and .Dark.
Autocomplete and the compiler only search the expected type and its inherited members. They exclude:
- Instance properties.
- Shared methods.
- Inaccessible properties.
- Shared properties whose return type is incompatible with the expected type.
A broad or ambiguous context still produces an error because there is no specific type to search. For example:
Print(.Red)
does not work when Print accepts Object; the full Colour.Red spelling is required there.