diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2010-06-10 06:06:12 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2010-06-10 06:06:12 +0000 |
commit | 1a317ff3dbc032a5410437ce2f86c3712434c984 (patch) | |
tree | 3b2f03900e9d3c504ede79d634a52799d32fc3eb | |
parent | f67c0fa12c35026d804bf9ccafa0ca464106a403 (diff) | |
download | swig-1a317ff3dbc032a5410437ce2f86c3712434c984.tar.gz |
Add C# example showing how to modify the underlying enum type
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12111 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r-- | Doc/Manual/CSharp.html | 33 | ||||
-rw-r--r-- | Examples/test-suite/csharp_typemaps.i | 7 |
2 files changed, 40 insertions, 0 deletions
diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index ea8b66e65..909357f37 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -38,6 +38,7 @@ <li><a href="#CSharp_date_properties">A date example demonstrating marshalling of C# properties</a> <li><a href="#CSharp_partial_classes">Turning wrapped classes into partial classes</a> <li><a href="#CSharp_extending_proxy_class">Extending proxy classes with additional C# code</a> +<li><a href="#CSharp_enum_underlying_type">Underlying type for enums</a> </ul> </ul> </div> @@ -2400,6 +2401,38 @@ public class ExtendMe : IDisposable { </pre> </div> +<H3><a name="CSharp_enum_underlying_type"></a>18.6.7 Underlying type for enums</H3> + + +<P> +C# enums use int as the underlying type for each enum item. +If you wish to change the underlying type to something else, then use the <tt>csbase</tt> typemap. +For example when your C++ code uses a value larget than int, this is necessary as the C# compiler will not compile values which are too large to fit into an int. +Here is an example: +</p> + +<div class="code"> +<pre> +%typemap(csbase) BigNumbers "uint" +%inline %{ + enum BigNumbers { big=0x80000000, bigger }; +%} +</pre> +</div> + +<p> +The generated enum will then use the given underlying type and compile correctly: +</p> + +<div class="code"> +<pre> +public enum BigNumbers : uint { + big = 0x80000000, + bigger +} +</pre> +</div> + </body> </html> diff --git a/Examples/test-suite/csharp_typemaps.i b/Examples/test-suite/csharp_typemaps.i index b940f25a3..18896456e 100644 --- a/Examples/test-suite/csharp_typemaps.i +++ b/Examples/test-suite/csharp_typemaps.i @@ -110,3 +110,10 @@ struct WasCrashing {}; void hoop(WasCrashing was) {} %} + +// Enum underlying type +%typemap(csbase) BigNumbers "uint" +%inline %{ +enum BigNumbers { big=0x80000000, bigger }; +%} + |