Merge pull request #1142 from jder/csharp-doc-fix
Copy over Java documentation changes on possible GC issues to C# docs
This commit is contained in:
commit
6ec5d03947
1 changed files with 27 additions and 14 deletions
|
|
@ -2019,37 +2019,50 @@ public class Container : global::System.IDisposable {
|
||||||
// Ensure that the GC doesn't collect any Element set from C#
|
// Ensure that the GC doesn't collect any Element set from C#
|
||||||
// as the underlying C++ class stores a shallow copy
|
// as the underlying C++ class stores a shallow copy
|
||||||
private Element elementReference;
|
private Element elementReference;
|
||||||
private global::System.Runtime.InteropServices.HandleRef getCPtrAndAddReference(Element element) {
|
|
||||||
elementReference = element;
|
|
||||||
return Element.getCPtr(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setElement(Element e) {
|
public void setElement(Element e) {
|
||||||
examplePINVOKE.Container_setElement(swigCPtr, getCPtrAndAddReference(e));
|
examplePINVOKE.Container_setElement(swigCPtr, Element.getCPtr(e));
|
||||||
|
elementReference = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The following typemaps will generate the desired code.
|
The following typemaps can be used to generate this code:
|
||||||
The 'csin' typemap matches the input parameter type for the <tt>setElement</tt> method.
|
|
||||||
The 'cscode' typemap simply adds in the specified code into the C# proxy class.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(csin) Element *e "getCPtrAndAddReference($csinput)"
|
|
||||||
|
|
||||||
%typemap(cscode) Container %{
|
%typemap(cscode) Container %{
|
||||||
// Ensure that the GC doesn't collect any Element set from C#
|
// Ensure that the GC doesn't collect any Element set from C#
|
||||||
// as the underlying C++ class stores a shallow copy
|
// as the underlying C++ class stores a shallow copy
|
||||||
private Element elementReference;
|
private Element elementReference;
|
||||||
private global::System.Runtime.InteropServices.HandleRef getCPtrAndAddReference(Element element) {
|
|
||||||
elementReference = element;
|
|
||||||
return Element.getCPtr(element);
|
|
||||||
}
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
%typemap(csin,
|
||||||
|
post=" elementReference = $csinput;"
|
||||||
|
) Element *e "Element.getCPtr($csinput)"
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The 'cscode' typemap simply adds in the specified code into the C# proxy class.
|
||||||
|
The 'csin' typemap matches the input parameter type and name for the <tt>setElement</tt> method and
|
||||||
|
the 'post' typemap attribute allows adding code after the PInvoke call.
|
||||||
|
The 'post' code is generated into a finally block after the PInvoke call so the resulting code isn't quite
|
||||||
|
as mentioned earlier, <tt>setElement</tt> is actually:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
public void setElement(Element e) {
|
||||||
|
try {
|
||||||
|
examplePINVOKE.Container_setElement(swigCPtr, Element.getCPtr(e));
|
||||||
|
} finally {
|
||||||
|
elementReference = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue