Can't do (expression yielding System.Type)object cast?
<p>I've got an object[] array which contains some mixture of builtin types, like Int/Byte/String,  and I'm trying to cast at runtime from object to the correct type,  then handing that casted data to a 3rd party library that has Write(builtin type overloads) method.</p>

<p>I thought I could just do Obj.Write((expression yielding System.Type)objArg),  but it errors on me.</p>

<p>Here's a code sample that explains it better:</p>

<pre><code>    object testData = (int)42;
    int final = (GetAType())testData;

    private Type GetAType()
    {
        return typeof(Int32);
    }
</code></pre>

<p>Any suggestions?
Alternate ways to accomplish this would be helpful also.</p>

<p>For some context,  here's my original problem.
3rd party library with a bunch of overloads for different types.</p>

<pre><code>3rdPartyLibrary.Write(bool source)
3rdPartyLibrary.Write(int16 source)
3rdPartyLibrary.Write(int32 source)
3rdPartyLibrary.Write(string source)
</code></pre>

<p>I'm trying to abstract a layer between 3rdPartyLibrary and the rest of my code</p>

<pre><code>Such that I can have
Object[int32]
Object[int16]
Object[string]
Object[int32]
</code></pre>

<p>I'm trying to do something simple seeming, like this (psuedo-coded)</p>

<pre><code>loop Object[]
{
  3rdPartyLibrary.Write( (object[i].GetType()) object[i] )
}
</code></pre>

<p>I've been reading all the similar sounding question, it looks like this may not be possible?</p>
