Type of Anytpe enum
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(...) : ... } } |
Tags: Data Types, Dynamics AX, Programming, X++
This entry was posted on Tuesday, April 14th, 2009 at 23:20 and is filed under Dynamics AX. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

