title: How to convert a user-defined unmanaged type to a managed type?
body: <p>I have a test that I'm writing in MSTest, which is managed C++, and I'm trying to test an unmanaged class. Specifically, I'm trying to use the PrivateObject class to call a private method.</p>
  
  <p>This is the code that I have so far:</p>
  
  <pre><code>CUnmanagedType foo;
  PrivateObject privateFoo = gcnew PrivateObject( foo );
  
  CString strFromFoo = privateFoo.Invoke( "ARandomPrivateMethod" );
  </code></pre>
  
  <p>When I compile I get an error that foo is not convertable to System::Type^. I've tried doing the following:</p>
  
  <pre><code>PrivateObject privateFoo = gcnew PrivateObject( (gcnew System::Type^(foo)) );
  </code></pre>
  
  <p>but that won't work because System::Type^ is an abstract type. Any ideas?</p>
  
  <p>I've looked at these questions, but they used pre-defined types, not user-defined ones:
  <a href="https://stackoverflow.com/questions/103298/how-to-convert-a-unmanaged-double-to-a-managed-string">How to convert a unmanaged double to a managed string?</a>
  <a href="https://stackoverflow.com/questions/741245/conversion-between-managed-and-unmanaged-types-in-c">Conversion between managed and unmanaged types in C++?</a></p>