How do I use SWIG to generate a C# interface (or at least a C# mock-able base class) from C++ using SWIG?
Given:
C++:
class IWidget
{
public:
virtual void Flob() = 0;
};
class Widget : public IWidget
{
public:
void Flob() {};
};
I would like to output C#:
public interface IWidget
{
void Flob();
}
public class Widget : IWidget
{...}
Note: Solution does not have to be an interface, but I do need to be able to use mocking frameworks such as Moq or Rhino.Mocks to mock out the base of the C# Widget class. My attempts only yielded generated C# with no public constructors.
codegen options files function -args {func_inputs} generates C/C++ code from a MATLAB function that uses custom source code specified in external files. For more information, see Call Custom C/C++ Code from the Generated Code and Configure Build for External C/C++ Code.
When used with the -config option, also generates single-precision C/C++ code. codegen generates the single-precision files in the folder codegen/target/folder_name folder_name is the concatenation of fcn_name and singlesuffix. singlesuffix is the suffix that the coder.SingleConfig property OutputFileNameSuffix specifies.
The rand () function in C could be used in order to generate the random number and the generated number is totally deleting seed. A seed is a value that is used by rand function to generate the random value.
Use the options argument to specify settings such as the code generation configuration object. The configuration object controls build type (MEX, lib, dll, or exe) and code generation parameters.
You may be able to get the output you list by using one or more of:
csclassmodifiers
%ignore
on the pure virtual methods, add necessary method declarations using cscode .csinterfaces typemap
csinterfaces_derived typemap
However this may not be the easiest way to achieve the goal of making your class mockable. Consider extending your post to clearly identify what is the c# that you need to achieve this if interface
is not used.
Also take a look at this post: http://swig.10945.n7.nabble.com/Multiple-inheritance-and-C-any-easy-workarounds-available-td11516.html.
Sorry I can't provide an actual code answer, hopefully the above gets you there.
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