Merge branch 'master' of https://github.com/BrantKyser/swig
- Remove using directives from the generated C# code and fully qualify the use of all .NET framework types in order to minimize potential name collisions from input files defining types, namespace, etc with the same name as .NET framework members. - Globally qualify the use of .NET framework types in the System namespace - Remove .NET 1.1 support, .NET 2 is the minimum for the C# module Closes #79 * 'master' of https://github.com/BrantKyser/swig: Correct spelling of compatibility. Update documentation to reflect fully qualifying the use of .NET types in the generated code. Add support for SWIG2_CSHARP macro to create SWIG 2 backwards compatability mode. Remove using directives from the generated C# code and fully qualify the use of all .NET framework types in order to minimize potential name collisions from input files defining types, namespace, etc with the same name as .NET framework members. Since SWIG 3.0 removes support for .NET 1.1, cleanup the C# library by removing the use of the SWIG_DOTNET_1 macro. Globablly qualify the use of types from the .NET framework's System namespace in the C# module and library. Add test case to demonstrate the name collision that occurs in the generated C# code when a namespace is named System.
This commit is contained in:
commit
c7b5316912
20 changed files with 434 additions and 369 deletions
|
|
@ -14,9 +14,11 @@ top_builddir = ../@top_builddir@
|
|||
|
||||
CPP_TEST_CASES = \
|
||||
csharp_attributes \
|
||||
csharp_swig2_compatibility \
|
||||
csharp_exceptions \
|
||||
csharp_features \
|
||||
csharp_lib_arrays \
|
||||
csharp_namespace_system_collision \
|
||||
csharp_prepost \
|
||||
csharp_typemaps \
|
||||
enum_thorough_simple \
|
||||
|
|
@ -35,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_compatibility.cpptest: SWIGOPT += -DSWIG2_CSHARP
|
||||
|
||||
# Rules for the different types of tests
|
||||
%.cpptest:
|
||||
|
|
|
|||
|
|
@ -82,17 +82,6 @@ public class li_std_vector_runme {
|
|||
} catch (ArgumentException) {
|
||||
}
|
||||
}
|
||||
#if SWIG_DOTNET_1
|
||||
{
|
||||
// runtime check that 2D arrays fail
|
||||
double[,] outputarray = new double[collectionSize,collectionSize];
|
||||
try {
|
||||
vect.CopyTo(outputarray);
|
||||
throw new Exception("CopyTo (5a) test failed");
|
||||
} catch (ArgumentException) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
{
|
||||
StructVector inputvector = new StructVector();
|
||||
int arrayLen = 10;
|
||||
|
|
@ -208,7 +197,6 @@ public class li_std_vector_runme {
|
|||
throw new Exception("Repeat (1) test failed");
|
||||
}
|
||||
}
|
||||
#if !SWIG_DOTNET_1
|
||||
{
|
||||
System.Collections.Generic.IEnumerator<double> myEnumerator = dv.GetEnumerator();
|
||||
while ( myEnumerator.MoveNext() ) {
|
||||
|
|
@ -216,7 +204,6 @@ public class li_std_vector_runme {
|
|||
throw new Exception("Repeat (2) test failed");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
|||
39
Examples/test-suite/csharp_namespace_system_collision.i
Normal file
39
Examples/test-suite/csharp_namespace_system_collision.i
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
%module namespace_system_collision
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
|
||||
namespace TopLevel
|
||||
{
|
||||
namespace System
|
||||
{
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
virtual std::string ping() { return "TopLevel::System::Foo::ping()"; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%include <std_string.i>
|
||||
|
||||
// nspace feature only supported by these languages
|
||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)
|
||||
%nspace;
|
||||
#else
|
||||
#warning nspace feature not yet supported in this target language
|
||||
#endif
|
||||
|
||||
namespace TopLevel
|
||||
{
|
||||
namespace System
|
||||
{
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo();
|
||||
virtual std::string ping();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -116,7 +116,7 @@ struct PrePost3 {
|
|||
// Check attributes in the typemaps
|
||||
%typemap(cstype, inattributes="[CustomInt]") int val "int"
|
||||
%typemap(csin, pre=" int tmp_$csinput = $csinput * 100;") int val "tmp_$csinput"
|
||||
%typemap(imtype, out="IntPtr/*overridden*/", outattributes="[CustomIntPtr]") CsinAttributes * "HandleRef/*overridden*/"
|
||||
%typemap(imtype, out="global::System.IntPtr/*overridden*/", outattributes="[CustomIntPtr]") CsinAttributes * "global::System.Runtime.InteropServices.HandleRef/*overridden*/"
|
||||
|
||||
%inline %{
|
||||
class CsinAttributes {
|
||||
|
|
@ -216,8 +216,8 @@ void subtractYears(CDate *pDate, int years) {
|
|||
%typemap(csvarout, excode=SWIGEXCODE2) CDate * %{
|
||||
/* csvarout typemap code */
|
||||
get {
|
||||
IntPtr cPtr = $imcall;
|
||||
CDate tempDate = (cPtr == IntPtr.Zero) ? null : new CDate(cPtr, $owner);$excode
|
||||
global::System.IntPtr cPtr = $imcall;
|
||||
CDate tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new CDate(cPtr, $owner);$excode
|
||||
return new System.DateTime(tempDate.getYear(), tempDate.getMonth(), tempDate.getDay(),
|
||||
0, 0, 0);
|
||||
} %}
|
||||
|
|
|
|||
48
Examples/test-suite/csharp_swig2_compatibility.i
Normal file
48
Examples/test-suite/csharp_swig2_compatibility.i
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
%module csharp_swig2_compatibility
|
||||
|
||||
%typemap(cscode) Foo %{
|
||||
|
||||
// Without the using directives generated by the
|
||||
// SWIG 2 compatibility 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 compatibility 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 compatibility mode, this code would fail
|
||||
// to build.
|
||||
public void ModuleClassMethod(string input)
|
||||
{
|
||||
Console.WriteLine(input);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
class Foo {
|
||||
public:
|
||||
Foo() {}
|
||||
|
||||
void Bar() {}
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ Number times12(const Number* num) {
|
|||
%typemap(csvarin, excode=SWIGEXCODE2) int %{
|
||||
set {
|
||||
if ($csinput < 0)
|
||||
throw new ApplicationException("number too small!");
|
||||
throw new global::System.ApplicationException("number too small!");
|
||||
$imcall;$excode
|
||||
} %}
|
||||
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ namespace Space {
|
|||
|
||||
#if defined(SWIGCSHARP)
|
||||
%typemap(cscode) Space::RenameMe %{
|
||||
public static NewName factory(String s) {
|
||||
public static NewName factory(System.String s) {
|
||||
//below should expand to:
|
||||
//return new NewName( new Name(s) );
|
||||
return new $typemap(cstype, Space::RenameMe)( new $typemap(cstype, Name)(s) );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue