Add %csattributes for adding C# attributes to enum values.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11693 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
272ed9fc29
commit
15070e6d8f
1 changed files with 33 additions and 1 deletions
|
|
@ -297,7 +297,7 @@ Note that all these different C# attributes can be combined so that a method has
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<p>
|
<p>
|
||||||
Support for attaching C# attributes to wrapped methods and variables.
|
Support for attaching C# attributes to wrapped methods, variables and enum values.
|
||||||
This is done using the <tt>%csattributes</tt> feature, see <a href="Customization.html#features">%feature directives</a>.
|
This is done using the <tt>%csattributes</tt> feature, see <a href="Customization.html#features">%feature directives</a>.
|
||||||
Note that C# attributes are attached to proxy classes and enums using the <tt>csattributes</tt> typemap.
|
Note that C# attributes are attached to proxy classes and enums using the <tt>csattributes</tt> typemap.
|
||||||
For example, imagine we have a custom attribute class, <tt>ThreadSafeAttribute</tt>, for labelling thread safety.
|
For example, imagine we have a custom attribute class, <tt>ThreadSafeAttribute</tt>, for labelling thread safety.
|
||||||
|
|
@ -344,6 +344,38 @@ they can be added using the 'csvarin' and 'csvarout' typemaps respectively.
|
||||||
Note that the type used for the property is specified in the 'cstype' typemap.
|
Note that the type used for the property is specified in the 'cstype' typemap.
|
||||||
If the 'out' attribute exists in this typemap, then the type used is from the 'out' attribute.
|
If the 'out' attribute exists in this typemap, then the type used is from the 'out' attribute.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
An example for attaching attributes to the enum and enum values is shown below.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
%typemap(csattributes) Couleur "[System.ComponentModel.Description(\"Colours\")]"
|
||||||
|
%csattributes Rouge "[System.ComponentModel.Description(\"Red\")]"
|
||||||
|
%csattributes Vert "[System.ComponentModel.Description(\"Green\")]"
|
||||||
|
%inline %{
|
||||||
|
enum Couleur { Rouge, Orange, Vert };
|
||||||
|
%}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
which will result in the following C# enum:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
[System.ComponentModel.Description("Colours")]
|
||||||
|
public enum Couleur {
|
||||||
|
[System.ComponentModel.Description("Red")]
|
||||||
|
Rouge,
|
||||||
|
Orange,
|
||||||
|
[System.ComponentModel.Description("Green")]
|
||||||
|
Vert
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue