viernes, 15 de julio de 2011

Enumerator value, it's symbol

I stumbled across an useful tid-bit of code on the web yesterday, courtesy of Preston A. Larimer.
/// enumName('valueCriteria', valueCriteria::Max) returns Max
static str enumName(str _Enum, anyType _enumValue)
{
   DictEnum dictEnum;
   ;
   dictEnum = new DictEnum(xutilelements::getNode(
       xutilelements::find(utilelementtype::Enum,_Enum)).applObjectId());

   return dictEnum.index2Symbol(_enumValue);
}
It took me so long to find as I was searching for the 'value' field but no matter what I did I was receiving the asociated translated text - ValueCriteria ⇒ "Maximum" in the above ejample.

There are no checks, however, so add them for empty parameter values.

Edit:  Ohh I just found a similar post where someone else not only got there first, but they arrived in a less sweaty state as well.
strfmt("%1", enum2symbol(enumnum(WorkTimeControl), workTimeControl));

No hay comentarios:

Publicar un comentario