ConfigType

Description

abstract class Tinman.Core.Config.ConfigType

Derived from

ConfigNode abstract
IEquatable<ConfigType>

Extended by

ArrayType sealed
ClassType sealed
EnumType sealed

Abstract base class for ConfigType implementations.

Public / Constants

Bool


[ShutdownSurvive]
public static readonly attribute Bool → (ConfigType)

Boolean type.

Invalid


[ShutdownSurvive]
public static readonly attribute Invalid → (ConfigType)

Void type (i.e. no value).

Num


[ShutdownSurvive]
public static readonly attribute Num → (ConfigType)

Decimal number type.

Path


[ShutdownSurvive]
public static readonly attribute Path → (ConfigType)

File path type.

Str


[ShutdownSurvive]
public static readonly attribute Str → (ConfigType)

String type.

Public / Constructors

Get


public static method Get → (1)

name in : string

[not-null]
The type name.

returns → ConfigType

The ConfigType object.

Returns a config type by its name.

ConfigException

If not found.

Get​Null


public static method GetNull → (3)

name in : string

The type name.

prefixes opt : IVectorConst<string> = null

Optional list of type name prefixes to use for resolving short names.

superClass opt : ClassType = null

Optional super class to use for determining the set of possible config types.

returns → ConfigType

The ConfigType object or null if not found.

Returns a config type by its name.

Lazy


public static method Lazy → (1)

name in : string

[not-empty]
The config type name.

returns → ConfigType

The lazy config type reference.

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.

Public / Methods

As​Array


public method AsArray → ()

returns → ArrayType

The cast type.

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.

As​Array​Null


[EmptyBody]
public virtual method AsArrayNull → ()

returns → ArrayType

The cast type or null if this is not an array type.

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.

As​Class


public method AsClass → ()

returns → ClassType

The cast type.

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.

As​Class​Null


[EmptyBody]
public virtual method AsClassNull → ()

returns → ClassType

The cast type or null if this is not a class type.

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.

As​Enum


public method AsEnum → ()

returns → EnumType

The cast type.

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.

As​Enum​Null


[EmptyBody]
public virtual method AsEnumNull → ()

returns → EnumType

The cast type or null if this is not an enum type.

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.

Coalesce


public static method Coalesce → (1)

type opt : ConfigType = null

The type or null.

returns → ConfigType

The resulting type.

Returns the invalid type if type opt is null.

Find​Usages


public static method FindUsages → (1)

type in : ConfigType

[not-null]
The type for which to return usages.

returns → ConfigMember [ ]

The usages.

Returns all ConfigMembers in all known ConfigTypes that use the given config type in their member value type (including nested array types).

Fix​Try

2 overloads


public method FixTry1 → (2)

value in : ConfigValue

[not-null]
The config value to fix.

superType opt : ConfigType = null

Optional super type to which the fixed value must be assignable to.

returns → bool

true if value in can be fixed, false if not.

Checks if the given config value can be fixed so that its type becomes convertible to this config type.


public method FixTry2 → (1)

expr in : ConfigExpression

[not-null]
The expression to fix.

returns → ConfigExpression

The fixed expression or expr in if fixing is not possible.

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.

Is​Assignable​To


public virtual method IsAssignableTo → (1)

other in : ConfigType

[not-null]
The other type.

returns → bool

true if this type is assignable to the given one, false if not.

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 type B iff the element type of A is assignable to the element type of B.

  • A class type A is assignable to a class type B iff B is an ancestor of A in the inheritance chain.

Is​Convertible​To


[EmptyBody]
public virtual method IsConvertibleTo → (2)

other in : ConfigType

[not-null]
The other config type.

always opt : bool = false

When set to true, the method will return true iff this type is always convertible to other in. When set to false, this method will return true even if a conversion might fail at runtime, causing a ConfigException to be thrown (e.g. invalid string to number).

returns → bool

true if this type is convertible to the given one, false if not.

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:

  1. An array type A is convertible to an array type B iff the element type of A is convertible to the element type of B.

  2. The negated result of ConfigValue.IsNull is used as the converted value.

  3. 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.

  4. true => 1, false => 0

  5. true => 'true', false => 'false'

  6. The ordinal value of the enum item (see EnumType.GetItemOrdinal) is used.

  7. The tag value of the enum item (see EnumItem.Tag) is used.

  8. 0 => false, all other values yield true.

  9. 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.

  10. The number is formatted as a string (using StringUtil.NumberFormat with round-trip precision):
    123.45 => '123.45'.

  11. Will be true iff the path value refers to an existing file or directory (depending on Path.IsTrailing).

  12. The path value is used for the assignment (see object.ToString).

  13. Will be false if the string is null, empty or consists only of whitespaces (see StringUtil.IsEmptyOrWhitespace).

  14. 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.

  15. The string value is parsed as a number (see StringUtil.NumberParse). Will be ConfigValue.Invalid for unparseable string values.

  16. The string value is converted to a Path (see Path.From). Will be ConfigValue.Invalid for bad path strings.

  17. 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).

New​Array


[Pure]
public method NewArray → ()

returns → ConfigValue

The empty array value.

Creates an empty array value using this ConfigType as element type.

This method just calls ToArray, Value and ConfigValue.New2 in sequence.

Resolve​Lazy


public virtual method ResolveLazy → ()

returns → ConfigType

The non-lazy config type or this if this config type cannot be resolved into a non-lazy one.

Resolves this config type into a non-lazy one, if possible.

Short​Name


public virtual method ShortName → (2)

prefixes opt : IVectorConst<string> = null

The name prefixes or null.

superClass opt : ClassType = null

The class hierarchy root to use for finding name clashes.

returns → string

The short name.

Returns the shortest non-ambiguous name for this config type.

To​Array


[Pure]
public virtual method ToArray → ()

returns → ArrayType

The array type.

Uses this type as the element type and returns the corresponding array type.

Value


public abstract method Value → ()

returns → ConfigValue

The created value object.

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

All


public static attribute All → (get)

value : ConfigType [ ]

[not-null]
Array of all known config types.

Returns all known config types, sorted by Name.

Api​Info


public attribute ApiInfo → (get)

value : ApiEntry

[not-null]
The ApiEntry object.

Creates an ApiEntry object that describes the API of this config type.

The following information is encoded in the ApiEntry object:

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
}

Can​Be​Null


public abstract attribute CanBeNull → (get)

value : bool

true if instances of this type can have the value null, false if not.

Can instances of this config type be null?

Documentation


public attribute Documentation → (get)

value : TypeDocNode

The documentation or null if not found.

Returns the documentation of this config type.

Is​Abstract


public virtual attribute IsAbstract → (get)

value : bool

true if this is an abstract type, false if not.

Is this an abstract type?

Abstract types cannot be instantiated via ConfigValue.New2.

Is​Array


public virtual attribute IsArray → (get)

value : bool

true if this is an array type, false if not.

Is this an array type?

Is​Boolean


public virtual attribute IsBoolean → (get)

value : bool

true if this is the type boolean, false if not.

Is this the type boolean?

See also

ConfigType.Bool

Is​Class


public virtual attribute IsClass → (get)

value : bool

true if this is a class type, false if not.

Is this a class type?

Is​Enum


public virtual attribute IsEnum → (get)

value : bool

true if this is an enum type, false if not.

Is this an enum type?

Is​Invalid


public virtual attribute IsInvalid → (get)

value : bool

true if this type is invalid, false if not.

Is this type invalid?

Is​Lazy


public virtual attribute IsLazy → (get)

value : bool

true if this is a lazy config type, false if it is a regular one.

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.

Is​Number


public virtual attribute IsNumber → (get)

value : bool

true if this is the type number, false if not.

Is this the type number?

See also

ConfigType.Num

Is​Path


public virtual attribute IsPath → (get)

value : bool

true if this is the type string, false if not.

Is this the type path?

See also

ConfigType.Path

Is​Simple


public attribute IsSimple → (get)

value : bool

true if this is a simple type, false if not.

Is this a simple type?

Is​String


public virtual attribute IsString → (get)

value : bool

true if this is the type string, false if not.

Is this the type string?

See also

ConfigType.Str

Is​Struct


public virtual attribute IsStruct → (get)

value : bool

true if this is a structure type, false if not.

Is this a structure type?

A struct is a non-abstract class type that has no subclasses and no super class.

Is​Valid


public attribute IsValid → (get)

value : bool

true if this type is valid, false if not.

Is this type valid?

Members


[EmptyBody]
public virtual attribute Members → (get)

value : ConfigMember [ ]

[not-null]
The type members.

Returns the type members.

Module


public attribute Module → (get)

value : TinmanModule

[not-null]
The module.

The module that owns this config type.

Name


public abstract attribute Name → (get)

value : string

[not-null]
The type name.

The human-readable name of this config type.

Protected / Constructors

Config​Type


protected constructor ConfigType → ()

Creates a new instance of ConfigType.