Question

I need to create a wrapper between C++ and C#. I have a function very similar to this:

virtual SOMEINTERFACE* MethodName(ATTRIBUTE_TYPE attribType = ATTRIBUTE_TYPE::ATTRIB_STANDARD) = 0;

The enum is declared like this:

enum class ATTRIBUTE_TYPE { 
    ATTRIB_STANDARD, 
    ATTRIB_LENGTH 
};

How do I wrap that ATTRIBUTE_TYPE enum?

Was it helpful?

Solution

Your C++ enum is defined like this:

enum class ATTRIBUTE_TYPE { 
    ATTRIB_STANDARD, 
    ATTRIB_LENGTH 
};

By default, enum class types are int sized. Which means that you can translate this to C# like so:

enum ATTRIBUTE_TYPE { 
    ATTRIB_STANDARD, 
    ATTRIB_LENGTH 
};

That's all there is to it. A C# enum is blittable and this C# enum maps exactly on to your C++ enum.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top