title: How can I define a typemap for SWIG, that converts a reference argument from C++ to C#
body: <p>I have a C++ library which provides the following enum and function:</p>
  
  <pre><code>typedef enum en{
    a,
    b
  }myEnum;
  
  int myFunction( myEnum &amp;varToSet )
  {
    varToSet = 1;
    return 0;
  }
  </code></pre>
  
  <p>The function in the C# Wrapper should look something like this:</p>
  
  <pre><code>public static int myFunction( ref myEnum varToSet )
  </code></pre>
  
  <p>I have tried to get this result by following typemap in the Swig interface file:</p>
  
  <pre><code>%typemap(cstype) myEnum &amp; "ref myEnum"
  %typemap(csin) myEnum &amp; %{ref $csinput%}  
  </code></pre>
  
  <p>Swig changed the type from <strong>SWIGTYPE_p_myEnum</strong> to <strong>ref myEnum</strong> in Wrapper.cs, but not in WrapperPINVOKE.cs. What am I missing here?</p>