ClassFromString
(Automatically adding template at the end of the page.)
(Updated Edited template to July 12, 2025.)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
<message>Write the content here to display this box</message>
When going meta, it is sometimes interesting to treat your system types as strings – and then treat those strings as types again.
When going meta, it is sometimes interesting to treat your system types as strings – and then treat those strings as types again.


Line 16: Line 17:
[[Category:OCL]]
[[Category:OCL]]
[[Category:Operators]]
[[Category:Operators]]
{{Edited|July|12|2024}}
{{Edited|July|12|2025}}

Latest revision as of 05:47, 20 January 2025

This page was created by Alexandra on 2018-10-17. Last edited by Edgar on 2025-01-20.

When going meta, it is sometimes interesting to treat your system types as strings – and then treat those strings as types again.

If you have a type, use the operator AsString to treat it as a string.

Until now, there was no way to go from a string back to a type. Now, there is ClassFromString.

Consider this model:

Classfromstring -1 .png

I had the requirement to list all the subclasses except the purple ones…

I added a tagged value to the purple and then did this:

ComponentSpecification.allSubClasses->select(x|x.ClassFromString.TaggedValue(‘TypeSort’)<>’SKIPTHIS’)

The result is a collection of strings with the selected subclasses.