ConfigType
Description
- Derived from
-
ConfigNode abstract
IEquatable<ConfigType> - Extended by
Abstract base class for ConfigType implementations.
Public / Constructors
Lazy
Returns a config type lazily.
When this method is called, the referred config type does not need to exist. It must have been created by the time the returned ConfigType is actually used, though.
- See also
Public / Methods
AsArray
Casts this config type to ArrayType.
A ConfigType object for which IsArray returns true
is not necessarily an instance of ArrayType, so instead of type casting, this method should be used.
- ConfigException
-
If this is not an array type.
- See also
AsArrayNull
Casts this config type to ArrayType.
A ConfigType object for which IsArray returns true
is not necessarily an instance of ArrayType, so instead of type casting, this method should be used.
- See also
AsClass
Casts this config type to ClassType.
A ConfigType object for which IsClass returns true
is not necessarily an instance of ClassType, so instead of type casting, this method should be used.
- ConfigException
-
If this is not a class type.
- See also
AsClassNull
Casts this config type to ClassType.
A ConfigType object for which IsClass returns true
is not necessarily an instance of ClassType, so instead of type casting, this method should be used.
- See also
AsEnum
Casts this config type to EnumType.
A ConfigType object for which IsEnum returns true
is not necessarily an instance of EnumType, so instead of type casting, this method should be used.
- ConfigException
-
If this is not an enum type.
- See also
AsEnumNull
Casts this config type to EnumType.
A ConfigType object for which IsEnum returns true
is not necessarily an instance of EnumType, so instead of type casting, this method should be used.
- See also
FindUsages
Returns all ConfigMembers in all known ConfigTypes that use the given config type in their member value type (including nested array types).
FixTry
2 overloads
Checks if the given config value can be fixed so that its type becomes convertible to this config type.
Tries to fix the given expression.
This class type is used as the expected type. The method tries to find a distinct sequence of syntactic fixes so that the expression type becomes convertible to this class type.
IsAssignableTo
Checks if this config type is assignable to the given type.
Equal types are always assignable to each other (see IEquatable.Equals). Additionally, a type A
is assignable to a type B
if one of these conditions are met:
-
An array type
A
is assignable to an array typeB
iff the element type ofA
is assignable to the element type ofB
. -
A class type
A
is assignable to a class typeB
iffB
is an ancestor ofA
in the inheritance chain.
IsConvertibleTo
Checks if this config type is convertible to the given type (i.e. possibly failing, possibly lossy implicit conversion).
The following table shows the types A
that are convertible to the types B
:
A \ B | Array | Bool | Class | Enum | Num | Path | Str | ------+-------+-------+-------+-------+-------+-------+-------+ Array | (1) | (2) | | | | | (3) | ------+-------+-------+-------+-------+-------+-------+-------+ Bool | | (17) | | | (4) | | (5) | ------+-------+-------+-------+-------+-------+-------+-------+ Class | | (2) | (17) | | | | | ------+-------+-------+-------+-------+-------+-------+-------+ Enum | | | | (17) | (6) | | (7) | ------+-------+-------+-------+-------+-------+-------+-------+ Num | | (8) | | (9) | (17) | | (10) | ------+-------+-------+-------+-------+-------+-------+-------+ Path | | (11) | | | | (17) | (12) | ------+-------+-------+-------+-------+-------+-------+-------+ Str | | (13) | | (14) | (15) | (16) | (17) |
Two types that are assignable will always be convertible. A failed conversion attempt will yield ConfigValue.Invalid values.
The conversions outlined above are explained here:
-
An array type
A
is convertible to an array typeB
iff the element type ofA
is convertible to the element type ofB
. -
The negated result of ConfigValue.IsNull is used as the converted value.
-
Each array element is converted to
Str
and the resulting tokens are concatenated using','
as the glue. If one or more array elements cannot be converted, the result will be ConfigValue.Invalid. -
true
=>1
,false
=>0
-
true
=>'true'
,false
=>'false'
-
The ordinal value of the enum item (see EnumType.GetItemOrdinal) is used.
-
The tag value of the enum item (see EnumItem.Tag) is used.
-
0
=>false
, all other values yieldtrue
. -
The number is used as the enum item ordinal value (see EnumType.GetItem). Will result in ConfigValue.Invalid if the number lies outside of the range of valid ordinal values.
-
The number is formatted as a string (using StringUtil.NumberFormat with round-trip precision):
123.45
=>'123.45'
. -
Will be
true
iff the path value refers to an existing file or directory (depending on Path.IsTrailing). -
The path value is used for the assignment (see object.ToString).
-
Will be
false
if the string isnull
, empty or consists only of whitespaces (see StringUtil.IsEmptyOrWhitespace). -
If the string value is equal to the tag of an enum item (see EnumItem.Tag), that enum item will be used. Will be ConfigValue.Invalid if not found.
-
The string value is parsed as a number (see StringUtil.NumberParse). Will be ConfigValue.Invalid for unparseable string values.
-
The string value is converted to a Path (see Path.From). Will be ConfigValue.Invalid for bad path strings.
-
Assignable types (see IsAssignableTo) are always convertible.
When a conversion fails and the result is ConfigValue.Invalid, a ConfigException will be thrown, unless the conversion took place during evaluation of a config expression (see ConfigExpression.Evaluate).
NewArray
Creates an empty array value using this ConfigType as element type.
This method just calls ToArray, Value and ConfigValue.New2 in sequence.
Value
Creates a new value object for this config property type.
The returned value object will have the default value for its type. A class type value must be initialized to a concrete type before its fields can be accessed. This is done by calling ConfigValue.New2.
Public / Attributes
ApiInfo
Creates an ApiEntry object that describes the API of this config type.
The following information is encoded in the ApiEntry object:
-
ApiEntry.NamePlain is equal to Name.
-
ApiEntry.NameSuffix is equal to ShortName.
-
If IsStruct returns
true
, the tagstruct
is added. Otherwise, if IsAbstract returnstrue
, the tagabstract
is added. Otherwise, if IsClass returnstrue
, the tagclass
is added. -
If IsClass returns
true
, the Name of ClassType.SuperClass is added as a type, if it is not ClassType.Obj. -
If IsEnum returns
true
, the tagenum
is added. For each item in EnumType.Items, a child API entry is added, where ApiEntry.Name is equal to ConfigItem.Name and ApiEntry.Value is equal to EnumItem.Tag. -
If IsEnum returns
false
, a child API entry is added for each member in Members, where ApiEntry.Name is equal to ConfigItem.Name and ApiEntry.Value is equal to the source code of ConfigMember.Value. If ConfigMember.IsVirtual returnstrue
, the tagvirtual
is added. If ConfigMember.Constraint is notnull
, a tag in the form[expr]
is added, whereexpr
is the source code of ConfigMember.Constraint. The Name of ConfigItem.Type is added as a type.
This is an example for a ConfigType where IsStruct returns true
:
Tinman.Math.(Vec3) @ struct { x : number, y : number, z : number }
This is an example for a ConfigType where IsAbstract returns true
:
Tinman.(Heightmap) @ abstract : Tinman.Dataset { id @ virtual : Tinman.Dataset.Id, metadata @ virtual : Tinman.Dataset.Info, georef @ virtual : Tinman.Georef, info @ virtual : Tinman.Heightmap.Info }
This is an example for a ConfigType where IsAbstract returns true
:
Tinman.(Image.File) @ class : Tinman.Image { data @ [# != null] : Tinman.Data, format : string = 'Any', info @ virtual : Tinman.Image.Info }
This is an example for a ConfigType where IsEnum returns true
:
Tinman.(Dataset.Mode) @ enum { Open, Create, Update }
IsLazy
Is this config type lazy?
Lazy config types are created by calling Lazy; they refer to a config type by its fully-qualified name. Lazy config types are not present in the global config type registry (see Get). A lazy type can be converted into a regular type by calling ResolveLazy.