title: Convert Object to the C++ built-in type
body: <p>I have the following minimal code:</p>
  
  <pre><code>using namespace System;
  
  long get_prop( Object^ v )
  {
      return Convert::ToInt32( v );
  }
  
  int main()
  {
      Object^ o1 = gcnew Int32( -1 );
      Object^ o2 = gcnew UInt32( 0xFFFFFFFF );
      long value1 = get_prop( o1 );
      long value2 = get_prop( o2 );
  
      return 0;
  }
  </code></pre>
  
  <p>It gives the <code>OverflowException</code> exception in <code>get_prop</code> function. In the end I need to use the result of <code>get_prop</code> in pure C++ code. What is the correct way to write <code>get_prop</code> function so it can work without exception in both cases. Can I use some sort of templates as in C++ or there more trivial solution?</p>