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 ?
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;
}
}
I think enums don't use the ^ -- try removing it from the property declaration and get().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With