Type reflection in ASIL is done via the Type and TypeInstance classes. (TypeInstance contains a Type reference and is used to differentiate between various types of references and value instances. Variables like ref int
and int
share the same Type instance, but different TypeInstance instances.)
It doesn't matter if you declare a variable with or without a type shortcut. Both var int i
and var i%
share the same Type instance.
type
member in every typeEvery type, including primitives, has a special member called type. (If you need "type" as the name of a member or method, you'll need to declare it with the new keyword.) This is a TypeInstance instance and can be compared with a Type instance. You can explicitly access the Type instance with "type.declaration
".
Unlike other languages, ASIL doesn't need a special operator to turn a type name into the type used for reflection. If the parser encounters a type name where a type name wasn't expected, it tries the corresponding Type instance instead. So "int = 2.type.declaration
" is a true expression. This includes the identifier for a generic type parameter. The Type class will be comparable to those in other languages.
Type aliases pose a special challenge. A TypeAlias has a class very similar to TypeInstance called TypeAlias. However, a TypeAlias can be based on another TypeAlias as long as there are no circular references.