开发者

How to use Enumerations in DXL Scripts?

I'd like to test the value of an enumeration attribute of a DOORs object. How can this be done? And where can I find a DXL 开发者_StackOverflowdocumentation describing basic features like this?

if (o."Progress" == 0) // This does NOT work
{
  // do something
}


So after two weeks and an expired bounty I finally made it. Enum-Attributes can be assigned to int or string variables as desired. But you have to assign to a variable to perform such a conversion. It is not casted when a mere comparison is done like in my example. So here comes the solution:

int tmp = o."Progress"
if (tmp == 0)
{
  // do something
}

When tmp is a string, a comparison to the enum literals is possible.

That was easy. Wasn't it? And here I finally found the everything-you-need-to-know-about-DXL manual.


For multi-valued enumerations, the best way is if (isMember(o."Progress", "0")) {. The possible enumerations for single and multi-enumeration variables are considered strings, so Steve's solution is the best dxl way for the single enumeration.


You can also do

if(o."Progress" "" == "0")
{
   //do something
}

This will cast the attribute value to a string and compare it to the string "0"


If you're talking about the "related number" that is assignable from the Edit Types box, then you'll need to start by getting the position of the enumeration string within the enum and then retrieve EnumName[k].value .

I'm no expert at DXL, so the only way to find the index that I know of off the top of my head is to loop over 1 : EnumName.size and when you get a match to the enumeration string, use that loop index value to retrieve the enumeration "related number."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜