tags:

views:

327

answers:

2

I have an assembly, written in C++\CLI, which uses some of enumerations, provided by .Net. It has such kind of properties:

property System::ServiceProcess::ServiceControllerStatus ^ Status  
{  
    ServiceControllerStatus ^ get()  
    {  
        return (ServiceControllerStatus)_status->dwCurrentState;   
    }  
}

it works fine, but when i use this assembly from my C# code, type of this property is

System.Enum

and i have to make type-cast

 if ((ServiceControllerStatus)currentService.Status == ServiceControllerStatus.Running)
     //do smth

The question is simple: why is it so, and how to fix it ?

+1  A: 

I think enums don't use the ^ -- try removing it from the property declaration and get().

Lou Franco
+2  A: 

In C++/CLI ^ is like the analagous * in standard C++. Because enumerations are value types the ^ should not be included otherwise you will see them as System.Enum.

Remove the ^ and you will see the correct enumeration on C# side.

property System::ServiceProcess::ServiceControllerStatus Status  
{  
    System::ServiceProcess::ServiceControllerStatus get()  
    {  
        return (System::ServiceProcess::ServiceControllerStatus)_status->dwCurrentState;   
    }  
}
smink