title: c# - How to deserialize a generic list<T> when I don't know the type of (T)?
body: <p>for auditory reasons I stores the arguments of the business methods serialized into the database using the binaryformatter. </p>
  
  <p>The problem is that when an argument is a generic list I don't find the way to cast the deserialized object because I don't know the type, or If I will know the type I don't know how to cast the object at runtime.</p>
  
  <p>Anybody knows how to cast an object containing a generic list dinamically at runtime?</p>
  
  <p>I need to do this because I need to show the deserialized data in a property grid:</p>
  
  <pre><code>object objArg = bformatter.Deserialize(memStr);
  
  //If the type is a clr type (int, string, etc)
  if (objArg.GetType().Module.Name == "mscorlib.dll")
  {                 
      //If the type is a generic type (List&lt;&gt;, etc) 
      //(I'm only use List for these cases)
      if (objArg.GetType().IsGenericType)
      {
           // here is the problem
           pgArgsIn.SelectedObject = new { Value = objArg};                    
  
           //In the previous line I need to do something like... 
           //new { Value = (List&lt;objArg.GetYpe()&gt;) objArg};
       }
       else
       {
           pgArgsIn.SelectedObject = new { Value = objArg.ToString() };                    
       }
  }
  else
  {
      //An entity object
      pgArgsIn.SelectedObject = objArg;                
  }
  </code></pre>