Add %feature("csdirectordelegatemodifiers") for C#

Enable customization of the delegate access modifiers generated in director classes.
Fixes https://github.com/swig/swig/issues/748
This commit is contained in:
William S Fulton 2016-12-24 17:14:36 +00:00
commit 01fa85bda7
3 changed files with 36 additions and 2 deletions

View file

@ -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.

View file

@ -1695,6 +1695,31 @@ void SwigDirector_Base::BaseBoolMethod(Base const &b, bool flag) {
</pre>
</div>
<p>
The delegates from the above example are <tt>public</tt> by default:
</p>
<div class="code">
<pre>
public delegate uint SwigDelegateBase_0(uint x);
public delegate void SwigDelegateBase_1(global::System.IntPtr b, bool flag);
</pre>
</div>
<p>
These can be changed if desired via the <tt>csdirectordelegatemodifiers</tt>
<a href="Customization.html#Customization_features">%feature directive</a>.
For example, using <tt>%feature("csdirectordelegatemodifiers") "internal"</tt>
before SWIG parses the Base class will change all the delegates to <tt>internal</tt>:
</p>
<div class="code">
<pre>
internal delegate uint SwigDelegateBase_0(uint x);
internal delegate void SwigDelegateBase_1(global::System.IntPtr b, bool flag);
</pre>
</div>
<H3><a name="CSharp_director_caveats">20.6.3 Director caveats</a></H3>

View file

@ -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));
}