Enumerations
No edit summary
No edit summary
Line 7: Line 7:
For example, you can return a list of the values. This returns a collection of ImportColumn [[Tuple]]<nowiki/>s.
For example, you can return a list of the values. This returns a collection of ImportColumn [[Tuple]]<nowiki/>s.
  ImportColumn.allInstances
  ImportColumn.allInstances
Converting this to a list of strings for each Enum value (for example to be used in a list on screen):
Convert this to a list of strings for each Enum value (for example to be used in a list on screen):
  ImportColumn.allInstances.asString
  ImportColumn.allInstances.asString


===== Select an enum value from the list, then get the string value from that: =====
===== Select an Enum value from the list, then get the string value from that: =====
  ImportColumn.allInstances->select(ic|ic = #JournalName).asString
  ImportColumn.allInstances->select(ic|ic = #JournalName).asString


===== Getting the value of an Enum [[tuple]]: =====
===== Get the value of an Enum [[tuple]]: =====
  (#JournalName).toString
  (#JournalName).toString
('''note: asString''' does not work on enum tuples)
('''note: asString''' does not work on Enum tuples)


===== Checking if a collection includes a value =====
===== Checking if a collection includes a value =====
You can't use the [[OCLOperators includes|includes]] operator on collections of enum. You have to select the value and check if you get a "hit".
You can't use the [[OCLOperators includes|includes]] operator on collections of Enum. You have to select the value and check if you get a "hit".


This works:
This works:

Revision as of 05:47, 19 June 2023

You can edit enumerations by right-clicking on any model element in the "model content" window.

Edit enumerations menu.png

The enumeration editing window:

Defining enumerations.png

The defined enumeration is a class in the model's type system.

For example, you can return a list of the values. This returns a collection of ImportColumn Tuples.

ImportColumn.allInstances

Convert this to a list of strings for each Enum value (for example to be used in a list on screen):

ImportColumn.allInstances.asString
Select an Enum value from the list, then get the string value from that:
ImportColumn.allInstances->select(ic|ic = #JournalName).asString
Get the value of an Enum tuple:
(#JournalName).toString

(note: asString does not work on Enum tuples)

Checking if a collection includes a value

You can't use the includes operator on collections of Enum. You have to select the value and check if you get a "hit".

This works:

SysSingleton.SO.ActiveUser.UserModes->select(x|x = #Consultant)->notEmpty

This does not work: SysSingleton.SO.ActiveUser.UserModes->includes(#Consultant)

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