Add support for SWIG2_CSHARP macro to create SWIG 2 backwards compatability mode.

This commit is contained in:
Brant K. Kyser 2013-10-21 13:13:47 -05:00
commit 3720b48847
3 changed files with 68 additions and 0 deletions

View file

@ -14,6 +14,7 @@ top_builddir = ../@top_builddir@
CPP_TEST_CASES = \
csharp_attributes \
csharp_swig2_compatability \
csharp_exceptions \
csharp_features \
csharp_lib_arrays \
@ -36,6 +37,7 @@ CSHARPFLAGSSPECIAL =
# Custom tests - tests with additional commandline options
intermediary_classname.cpptest: SWIGOPT += -dllimport intermediary_classname
csharp_lib_arrays.cpptest: CSHARPFLAGSSPECIAL = -unsafe
csharp_swig2_compatability.cpptest: SWIGOPT += -DSWIG2_CSHARP
# Rules for the different types of tests
%.cpptest:

View file

@ -0,0 +1,48 @@
%module csharp_swig2_compatability
%typemap(cscode) Foo %{
// Without the using directives generated by the
// SWIG 2 compatability mode, this code would fail
// to build.
public void FooBar(string input)
{
Console.WriteLine(input);
}
%}
%pragma(csharp) imclasscode=%{
// Without the using directives generated by the
// SWIG 2 compatability mode, this code would fail
// to build.
public void IntermediateClassMethod(string input)
{
Console.WriteLine(input);
}
%}
%pragma(csharp) modulecode=%{
// Without the using directives generated by the
// SWIG 2 compatability mode, this code would fail
// to build.
public void ModuleClassMethod(string input)
{
Console.WriteLine(input);
}
%}
%inline %{
class Foo {
public:
Foo() {}
void Bar() {}
};
%}

View file

@ -11,6 +11,24 @@
* The imtype typemap contains the C# type used in the intermediary class.
* The cstype typemap contains the C# type used in the C# proxy classes, type wrapper classes and module class. */
/* SWIG 3 no longer inserts using directives into generated C# code. For backwards compatability, the SWIG2_CSHARP
macro can be defined to have SWIG 3 generate using directives similar to those generated by SWIG 2. */
#ifdef SWIG2_CSHARP
%typemap(csimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "\nusing global::System;\nusing global::System.Runtime.InteropServices;\n"
%pragma(csharp) moduleimports=%{
using global::System;
using global::System.Runtime.InteropServices;
%}
%pragma(csharp) imclassimports=%{
using global::System;
using global::System.Runtime.InteropServices;
%}
#endif
/* Fragments */
%fragment("SWIG_PackData", "header") {