Another possible solution (in addition to all_values()
) is with reflection. Given a rf_enum
, we can call its get_items()
method to get a list of all enum items.
However, there are some differences between the refleciton soluition and all_values()
, which are important to know.
One difference is that if some enum items are given explicit numeric values, not necessarily in increasing order, then all_values()
will return the values in increasing order, but rf_enum.get_items()
will return the items in the order of declaration.
For example, if we have:
type foo: [A=5, B, C=1, D];
then all_values(foo)
will return C, D, A, B (in this order - according to the respective numeric values 1, 2, 5, 6), but rf_manager.get_type_by_name("foo").as_a(rf_enum).get_items()
will return A, B, C, D.
If you want to get the reflection result sorted by the numeric values, you can do, for example, rf_manager.get_type_by_name("foo").as_a(rf_enum).get_items().sort(it.get_value())
.
Another difference is that when we have several enumerated types based on each other, with different generative sub-ranges, then all_values()
for a specific type will return only values that belong to that types's generative range, but rf_enum.get_items()
will return all items.
For example:
type t1: [A, B, C, D];
type t2: t1[A..B];
type t3: t2;
extend t2: [E];
With this example, rf_enum.get_items()
will return A, B, C, D, E for any of t1, t2, or t3. But all_values()
will give different results, according to the generative range of each type. all_values(t1)
will return A, B, C, D; all_values(t2)
will return A, B, E; and all_values(t3)
will return A, B.