- simpler iteration of variables (struct members)
- easier to access and set new variables in structs
- possible to change which variables are members without having to hard-code each field
You can create arrays of any data type to store more than one value at the same time like this:
String[] s1;. For a given array, all items must be of the same type. Read more about looping and accessing array items in the fundamentals section.Type and value
String getTypeName(Generic generic)
getTypeName() returns the type of a variable.
Generic getGenericValue(String name)
getGenericValue() returns a variable from the run-time environment given its name and independent of its type.
If the variable name is unknown, an exceptions is thrown.
Down-casting
You can convert a Generic variable to these basic types.- Bool GenericToBool(Generic generic)
- Integer GenericToInteger(Generic generic)
- Float GenericToFloat(Generic generic)
- String GenericToString(Generic generic)
- DateTime GenericToDateTime(Generic generic)
- Date GenericToDate(Generic generic)
- Time GenericToTime(Generic generic)
- TimeSpan GenericToTimeSpan(Generic generic)
- Byte GenericToByte(Generic generic)
- Generic[] GenericToArray(Generic generic)
getTypeName(), these methods can be used to create an explicit typed variable.
Generic and arrays
Integer getTypeDimensions(Generic generic)
getTypeDimensions() returns the number of array dimensions for a variable. The argument is automatically up-casted to a Generic.
This is the number of dimensions in, not the length of, the array!
Generic and structs
The following examples build on this Person struct:Bool typeIsStruct(Generic generic)
typeIsStruct() checks whether a variable is a struct.
Check whether a variable is a struct or not. The argument is automatically up-casted to a Generic.
String[] getStructMembers(String name)
getStructMembers() returns the variable names of a struct given its name.
This is the names, not the actual values. To get those, call
getGenericValue() using the member names.Generic getGenericValue(Generic struct, String name)
A variant ofgetGenericValue() that returns a variable from the run-time environment inside a struct given its name and independent of its type.
If the variable name is unknown or you’re not referencing a struct, an exceptions is thrown.
String convertGenericToString(Generic generic)
convertGenericToString() returns the string representation of a variable. The argument is automatically be up-casted to a Generic.
This works for all basic types. Complex types might can’t be serialized as easy, and might not support this conversion. In that case, they’ll return “[complex]”.
Void setGenericFromString(Generic generic, String value)
setGenericFromString() sets the value of a variable from a string.
It supports only basic types. Attempting to set an array or a complex type will throw an exception.
The value must be formatted according to the constructor of that type. Specifically, Date, DateTime, and Time must be on the YYYY-MM-DD HH:MI:SS format.
Print contents of struct for extra table
In this scenario, we’ve created an extra table called Building. It has multiple extra fields of different types.print() method in the struct, with 1 printLine() for every member, and manually converting each value to a string like this:
printGeneric() method and leverage the Generic struct methods: