You can use typeName when you need the type name of an OCL value as text, for example while inspecting a value in an expression or diagnostic.
Syntax
expression.OclType.typeNameOclType is the type information for the expression. typeName returns that information as a System.String.
Return value
| Expression | Returns |
|---|---|
expression.OclType.typeName
|
The data type information for expression, as System.String.
|
Example
The following expression obtains the type name for a string value:
vStringValue:String = 'SomeString'
vStringValue.OclType.typeNameThe expression returns:
System.String
OclType.asString returns the same value as OclType.typeName.
Inspect a value's type
Use typeName when the value is known only through an expression or variable and you need to inspect its type.
For example, given a variable named X:
let X = 2
X.OclType.typeNameThis asks for the type information of X and returns it as text. This is useful when you are checking what kind of value an expression produced during development or validation.
When to use typeName
Use typeName to:
- Verify that an expression produces the expected type.
- Inspect a value while debugging an OCL expression.
- Record or display type information as a string when an expression can produce different kinds of values.
- Check the type of a value that is computed dynamically or may be null.
typeName returns text; it does not itself perform a Boolean type test. When you need to test whether an object is a specified model class or one of its subtypes, use oclIsKindOf. To return only objects of a specified type from a collection, use filterOnType.
