Where Clause (Generics)
Specifies constraints to put on generic parameters.
Syntax
Where constraint [ , constraint ]…
Parts
constraint- One or more constraints to put on a generic parameter, with a comma between each.
Constraint
Long construct Short construct [ min_type { < | <= } ] type_parameter { < | <= } max_type[ min_type { < | <= } ] type_parameter [ { < | <= } max_type ]type_parameter Is { Class | Struct | Unit }[ Is { Class | Struct | Unit } ]type_parameter Does mandatory_trait[ Does mandatory_trait ]…type_parameter Constructor ( )[ Constructor ( ) ]Self { < | <= | Is } self_type(Not available) Short construct [ min_type { < | <= } ] type_parameter [ { < | <= } max_type ] [ Is { Class | Struct | Unit } ] [ Does mandatory_trait ]… [ Constructor ( ) ]type_parameter- One of the generic parameters given in a Type List.
max_type- The most basic class from which
type_parametercan inherit. Use<iftype_parametermust be a child ofmax_type, or<=to includemax_typealso. min_type- The most specialized class from which
type_parametercan inherit. Use<iftype_parametermust be a child ofmin_type, or<=to includemin_typealso. mandatory_trait- A trait that
type_parametermust implement. Is- Specifies that
type_parametermust be one of these:- A reference type (
Is Class) - A value type (
Is Struct) - A unit of measure (
Is Unit)
- A reference type (
Constructor- Specifies that
type_parametermust supply a default constructor. self_type- A class from which the applicable class must inherit. This constraint is available to classes and traits only.
Instructions
TODO
Examples
Class Dictionary[DataType, KeyType]
Where KeyType Does Compare Constructor()
Method Add d As DataType, k As KeyType
End Method
Method Find(k As KeyType) As DataType
End Method
End Class
Applicable to
- Class Statement
- Event Statement
- Function Statement
- Method Statement
- Struct Statement
- Sub Statement
- Trait Statement