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 constructShort 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_parameter can inherit. Use < if type_parameter must be a child of max_type, or <= to include max_type also.
min_type
The most specialized class from which type_parameter can inherit. Use < if type_parameter must be a child of min_type, or <= to include min_type also.
mandatory_trait
A trait that type_parameter must implement.
Is
Specifies that type_parameter must be one of these:
  • A reference type (Is Class)
  • A value type (Is Struct)
  • A unit of measure (Is Unit)
Constructor
Specifies that type_parameter must 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

Applies to

See also