title: Convert generic object list to non-generic type list
body: <p>I am trying to convert a <code>List</code> of <code>System.Object</code> objects to a <code>List</code> of strongly typed objects.</p>
  
  <p>Here is the error I am getting:</p>
  
  <blockquote>
    <p>Object of type 'System.Collections.Generic.List`1[System.Object]' cannot be converted to type 'System.Collections.Generic.List`1[TestApp.Tsc_Mrc_Step]'.</p>
  </blockquote>
  
  <p>The purpose is because I am writing a business data layer for my project that all you have to do is name your class and properties the same name as entities in  your database and the data layer will automatically populate referenced tables as types that are declared in the class.</p>
  
  <p>The business data layer uses reflection, generics and objects to deal with all of this.</p>
  
  <p>Below is the code I tried to put a List of objects into a List of known types. The thing is, the object is the known type but I pass it as an object....How do I convert it to the known type without knowing what it is?</p>
  
  <pre><code>            bool isCoollection = false;
              Type t = GetTypeInsideOfObjectByTypeName(o, tableName, out isCoollection);
  
              List&lt;object&gt; objectColl = new List&lt;object&gt;();
  
              object obj = Activator.CreateInstance(t);
              if (obj != null)
              {
                  PropertyInfo[] objectProps = obj.GetType().GetProperties();
                  foreach (PropertyInfo op in objectProps)
                  {
                      if (HasColumn(reader, op.Name))
                      {
                          op.SetValue(obj, reader[op.Name]);
                      }
                  }
  
                  if (isCoollection)
                  {
                      objectColl.Add(obj);
                  }
              }
  
              if (isCoollection)
              {
                  IEnumerable&lt;object&gt; objs = objectColl.AsEnumerable();
  
                  SetObject(o, objs);
              }
              else
              {
                  SetObject(o, obj);
              }
  </code></pre>
  
  <p>Here is SetObject:</p>
  
  <pre><code>            public static void SetObject(object parentObject, object newObject)
              {
                  PropertyInfo[] props = parentObject.GetType().GetProperties();
                  string typeName = newObject.GetType().Name;
                  foreach (PropertyInfo pi in props)
                  {
                      if (pi.PropertyType.Name.ToLower() == typeName.ToLower())
                      {
                          pi.SetValue(parentObject, newObject);
                      }
                      else if (!pi.PropertyType.IsValueType &amp;&amp; !pi.PropertyType.Namespace.ToLower().Contains("system"))
                      {
                          SetObject(pi.GetValue(parentObject), newObject);
                      }
                  }
              }
  </code></pre>