Casting of a Object* to an Enum value??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everybody!

I have a problem with letting the compiler accept the following code in Managed C++, see example below.

I have a logfile that contains statements about variuos actions taken during an installation.
The actions has a value of a enum type itemOper = {FileCopy, FileMerge, FolderOk, ...} that is written to the logfile
by Enum::GetName(__typeof(itemOper), oper). No FlagAttribute is used on this enum type.
When i later read the logfile I want to translate the text "FileCopy" back into a value of type itemOper.
It works fine in runtime with the debugger and the following code:

Object * item = Enum::Parse(__typeof(itemOper), S"FileCopy");

If I set a breakpoint at a line after this statement the debugger show that the variable item has the value "FileCopy", thats fine!!
Now to the problem. The compiler does not allow any cast's or a switch(oper) statement!!!.
It does not accept a "if (oper == itemOper::FileCopy)" and so on.

What to do, the base class Enum is usable at variuos points, but I'm stuck here.
Does anybody know how to "fool" the compiler or have the right solution??

/Thanks
 
Anders,

You have to unbox the value from the returned Object

itemOper oper = *dynamic_cast<__box itemOper*>(item);



Mattias
 
Back
Top