diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 6da7474ec..8852d96f1 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -29,6 +29,8 @@
+C# supports the notion of partial classes whereby a class definition can be split into more than one file. +It is possible to turn the wrapped C++ class into a partial C# class using the csclassmodifiers typemap. +Consider a C++ class called ExtendMe: +
+ +
+class ExtendMe {
+public:
+ int Part1() { return 1; }
+};
+
++The default C# proxy class generated is: +
+ +
+public class ExtendMe : IDisposable {
+ ...
+ public int Part1() {
+ ...
+ }
+}
+
++The default csclassmodifiers typemap shipped with SWIG is +
+ ++%typemap(csclassmodifiers) SWIGTYPE "public class" ++
+If instead we use the following typemap to override this for just the ExtendMe class: +
+ ++%typemap(csclassmodifiers) ExtendMe "public partial class" ++
+The C# proxy class becomes a partial class: +
+ +
+public partial class ExtendMe : IDisposable {
+ ...
+ public int Part1() {
+ ...
+ }
+}
+
++You can then of course declare another part of the partial class elsewhere, for example: +
+ +
+public partial class ExtendMe : IDisposable {
+ public int Part2() {
+ return 2;
+ }
+}
+
++and compile the following code: +
+ +
+ExtendMe em = new ExtendMe();
+Console.WriteLine("part1: {0}", em.Part1());
+Console.WriteLine("part2: {0}", em.Part2());
+
++demonstrating that the class contains methods calling both unmanaged code - Part1() and managed code - Part2(). +The following example is an alternative approach to adding managed code to the generated proxy class. +
+ ++The previous example showed how to use partial classes to add functionality to a generated C# proxy class. +It is also possible to extend a wrapped struct/class with C/C++ code by using the %extend directive. +A third approach is to add some C# methods into the generated proxy class with the cscode typemap. +If we declare the following typemap before SWIG parses the ExtendMe class used in the previous example +
+ +
+%typemap(cscode) ExtendMe %{
+ public int Part3() {
+ return 3;
+ }
+%}
+
+
++The generated C# proxy class will instead be: +
+ +
+public class ExtendMe : IDisposable {
+ ...
+ public int Part3() {
+ return 3;
+ }
+ public int Part1() {
+ ...
+ }
+}
+
+