Type of Anytpe enum

  • April 14, 2009
  • 0 Comments

Normaly you try to avoid using AnyType variables, but sometimes you are forced to use them. When you use a AnyType enum and you want to cast it to it’s actual data type, be sure you cast it to the right type to prevent stack-traces. You can get the enumId from a AnyType-enum by using the DictEnum::value2id(AnyType _value) -function. Then you can compare it with the enumnum(EnumType) to check if it is the right type.

In code this check could look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
static void testAnyTypeEnumCasting(Args _args)
{
    DocumentStatus  docStatus;
    Anytype         any = DocumentStatus::Invoice;
    ;
    switch (DictEnum::value2id(any))
    {
        case enumnum(DocumentStatus) :
            docStatus = any;
            break;
        case enumnum(...) :
            ...
    }
}