Declaring a parameter of 2 possible enumeration types


I have a specific method which needs to accept either a Tool or a Flag (both of them are defined enumerations).
At first, I tried with “Item as Enumeration” but the compiler complains “There’s no class with this name”. Albeit every enumeration being its own type, I thought the base was still an enumeration, but it looks like it’s not accepted as a parameter type.

So now I’m trying with variant. I don’t like using variants but this looks the only compiling way.
In the method, I must now determine whether the parameter is a Tool or a Flag. As with Enumeration as a parameter type, writing “If Item isa Tool then” fails with “There’s no class with this name”.
The VarType function is also not suitable for this.
I guess comparing the parameter against all possible values (if Item=Tool.Tool1 or item=Tool.Tool2) and deciding which type it is would compile, but obviously isn’t great.

I don’t want to mix both enumerations in the first place, but they can be used for the same parameter. Is the language just lacking a “base class” for enumerations/an operator to test against an enumeration type?
Since an enumeration can be passed as a parameter, I’d expect a “generic” enumeration (i.e. “any”) to be allowed too. :thinking:

What about overloading the method so one version accepts a Tool and the other a Flag?


Yes, I thought about that, and assumed it wouldn’t work because I’d still need to pass either parameter type to the method in the end (it’s an init method).

Thinking further, I can refactor this: create the object in either method (that accepts either type), set the type there and call a common method to continue initialisation.
Technically, it would work, but I find it “ugly” (for instance, I must create a new object in both methods; if I need to change the other parameters, I must do it on both variants of the method). Not a good OOP design, I’d say.

I’d prefer a single method that accepts several enumeration types, but, well…

Thank you, you lead me to a track to check!

Edit: actually, I’m now using the class’ constructor to define the type (so only the constructor has two variants for either enumeration type). It stays inline (… “as New MyItem(Tool.Tool1)”), and a single method is sufficient to init the object further.