ClassFromString
No edit summary
No edit summary
Line 3: Line 3:
If you have a type, use the operator AsString to treat it as a string.
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'''.
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 12: Line 12:


I added a tagged value to the purple and then did this:
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.
The result is a collection of strings with the selected subclasses.
[[Category:OCL]]
[[Category:OCL]]
[[Category:Operators]]
[[Category:Operators]]

Revision as of 07:10, 28 June 2023

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.

This page was edited 93 days ago on 02/10/2024. What links here