How to generate C# properties in Interfaces using SWIG

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to generate C# properties in Interfaces using SWIG

Chris.E
This post has NOT been accepted by the mailing list yet.
I want to generate a C# interface using SWIG 3.0.12. For public functions this works as expected. However if I try to add properties to the interface they are not part of the generated interface.

Is it possible to tell SWIG to add properties to the public interface?

Here is a minimal example:

My C++ class looks like:

class IA
{
  public:
    virtual std::string GetX() = 0;
    virtual void SetX(const std::string& x) = 0;

    virtual void MyFunction() = 0;
};

Using the following interface file:
%module example

%{
#include "IA.h"
%}

%include <std_string.i>
%include <attribute.i>
%include <swiginterface.i>

%attribute(IA, std::string, X, GetX, SetX);
%interface(IA);

%include "IA.h"

The generated IASwigInterface.cs looks like:

public interface IASwigInterface {
    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
    global::System.Runtime.InteropServices.HandleRef GetInterfaceCPtr();
    void MyFunction();
}

What I would expect SWIG to generate for the IASwigInterface.cs is something like:

public interface IASwigInterface {
    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
    global::System.Runtime.InteropServices.HandleRef GetInterfaceCPtr();
    void MyFunction();
    string X { get; set; } //<- I want the property to be part of the interface
}

Does anyone know how this can be achieved?

Thanks
Christof
Loading...