How to cast a generic Type T to a List of a specific type
<p>I have a method that takes as an argument a generic Type T. If T is of Type List, I would like to cast it to a List where Y is the type of element contained in T. I suspect I am misunderstanding the constraints of generic Types but any help would be appreciated.</p>

<p>Example:</p>

<pre><code>public void MapData&lt;T&gt;(T genericData)
{
   var genericDataType = genericData.GetType();

   if (genericDataType.Name.Contains("List"))
   {
      //Cast T to a List containing the type of elements contained in T
   }
 }
</code></pre>

<p>I need to cast genericData to a List so that I can pass it to another method with signature:</p>

<pre><code>public void MapListToField&lt;T&gt;(List&lt;T&gt; genericList) 
</code></pre>

<p><strong>UPDATE</strong></p>

<p>Per Eric's response below, I wanted to share an attempt I made that perhaps someone could point out my error. The compiler is stating that I am attempting to use a variable as a Type, which I understand the meaning of, but elementType IS a Type, so I'm unclear how to fix:</p>

<pre><code>var elementType = genericData.GetType().GetGenericArguments()[0];
var castedList = genericData as List&lt;elementType&gt;;
</code></pre>