ClassFromString
(Created page with "When going meta it is sometimes interesting to treat your system types as strings – and then be able to treat those strings as types again. If you have a type you use the o...") |
(Automatically adding template at the end of the page.) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
When going meta it is sometimes interesting to treat your system types as strings – and then | 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 | 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 | Until now, there was no way to go from a string back to a type. Now, there is '''ClassFromString'''. | ||
Consider this model: | Consider this model: | ||
Line 11: | Line 11: | ||
I had the requirement to list all the subclasses except the purple ones… | I had the requirement to list all the subclasses except the purple ones… | ||
I added a tagged value to the purple and then | I added a tagged value to the purple and then did this: | ||
ComponentSpecification.allSubClasses->select(x|x.ClassFromString.TaggedValue(‘TypeSort’)<>’SKIPTHIS’) | |||
ComponentSpecification.allSubClasses->select(x|x.ClassFromString.TaggedValue(‘TypeSort’)<>’SKIPTHIS’) | The result is a collection of strings with the selected subclasses. | ||
[[Category:OCL]] | [[Category:OCL]] | ||
[[Category:Operators]] | [[Category:Operators]] | ||
{{Edited|July|12|2024}} |
Latest revision as of 15:28, 10 February 2024
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:
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.
This page was edited more than 11 months ago on 02/10/2024. What links here