Vasliy
Vasliy

Reputation: 138

SWIG: wrap enum to c#

I can't wrap c++ enum member to C# using SWIG. The size of c++ enum members is exceed Int32. In C# default type of enum memeber is Int32, thus I have compilation error. Although I follow the instructions, I can't solve the problem.

MyClass.h

class  MyClass
{
public:
    MyClass() {}
    ~MyClass() {}
    enum  BigNumbers
    {
        big = 0x80000000, bigger
    };
};

MyClass.i

%module cpp

%{
    #include "MyClass.h"
%}
%include "MyClass.h"

%typemap(csbase) BigNumbers "uint"
%inline %{
  enum BigNumbers { big=0x80000000, bigger };
%}

As result i get follow member in generated c# wrapper, which cause compilation error cannot implicitly convert type 'uint' to 'int'

MyClass.cs

  public enum BigNumbers {
    big = 0x80000000,
    bigger
  } 

and global uint enum in separate file:

BigNumbers.cs

public enum BigNumbers : uint {
  big = 0x80000000,
  bigger
}

While I want to get it in MyClass.cs as member of MyClass.

Please, anyone help me!

Upvotes: 2

Views: 1212

Answers (1)

Vasliy
Vasliy

Reputation: 138

sorry for really dumb question, i should had to read the manual better.
Correct content of interface file is as follows:

MyClass.i

%module cpp

%{
    #include "MyClass.h"

%}
%typemap(csbase) somens::MyClass::BigNumbers "uint"
%include "MyClass.h"

Upvotes: 3

Related Questions