From 01fa85bda77b42655655aed9fbb7eb59466a395e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 24 Dec 2016 17:14:36 +0000 Subject: [PATCH] Add %feature("csdirectordelegatemodifiers") for C# Enable customization of the delegate access modifiers generated in director classes. Fixes https://github.com/swig/swig/issues/748 --- CHANGES.current | 5 +++++ Doc/Manual/CSharp.html | 25 +++++++++++++++++++++++++ Source/Modules/csharp.cxx | 8 ++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 118f112de..53ec34e54 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.11 (in progress) ============================ +2016-12-24: wsfulton + [C#] Add %feature("csdirectordelegatemodifiers") to enable customization + of the delegate access modifiers generated in director classes. + Fixes issue https://github.com/swig/swig/issues/748 + 2016-12-23: wsfulton [Python] Fix builtin "python:slot" feature failing for tp_hash when using hashfunc closure with a "Wrong type for hash function" for Python 2. diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 82f085101..2707cb4a6 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -1695,6 +1695,31 @@ void SwigDirector_Base::BaseBoolMethod(Base const &b, bool flag) { +

+The delegates from the above example are public by default: +

+ +
+
+  public delegate uint SwigDelegateBase_0(uint x);
+  public delegate void SwigDelegateBase_1(global::System.IntPtr b, bool flag);
+
+
+ +

+These can be changed if desired via the csdirectordelegatemodifiers +%feature directive. +For example, using %feature("csdirectordelegatemodifiers") "internal" +before SWIG parses the Base class will change all the delegates to internal: +

+ +
+
+  internal delegate uint SwigDelegateBase_0(uint x);
+  internal delegate void SwigDelegateBase_1(global::System.IntPtr b, bool flag);
+
+
+

20.6.3 Director caveats

diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 01fd5435b..086e626f6 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3917,8 +3917,12 @@ public: } Printf(callback_def, " private %s SwigDirector%s(", tm, overloaded_name); - if (!ignored_method) - Printf(director_delegate_definitions, " public delegate %s", tm); + if (!ignored_method) { + const String *csdirectordelegatemodifiers = Getattr(n, "feature:csdirectordelegatemodifiers"); + String *modifiers = (csdirectordelegatemodifiers ? NewStringf("%s%s", csdirectordelegatemodifiers, Len(csdirectordelegatemodifiers) > 0 ? " " : "") : NewStringf("public ")); + Printf(director_delegate_definitions, " %sdelegate %s", modifiers, tm); + Delete(modifiers); + } } else { Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0)); }