title: How do create a Generic Object using Reflection
body: <p>First let me say, that what I want to do is get the value of a property in a generic class that may be overriden by class that inherits from it. Think of it in the base class as a default value, that the inheritor of the class can override to set their own Default value.</p>
  
  <p>I have tried to use reflection directly on the type, using the System.Reflection.FieldInfo.GetValue but this does not work for classes with generic types. So I think that I need to instantiate the class to be able to see what the value is.</p>
  
  <p>The "types" I have I retrieved by reading the Dlls in the bin and using Reflection to find the types that inherit from my interface.</p>
  
  <p>I am using .NET 4.5 </p>
  
  <p>here is documentation that seems like it explains exactly what I need to do
  <a href="http://msdn.microsoft.com/en-us/library/b8ytshk6.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/b8ytshk6.aspx</a></p>
  
  <p>In this documentation the only difference I can see is how we got our types, I looked in the bin for types and they simply called typeof(), Since types are so complex it seems this may be a likely mis-match but I cannot see what is missing(if anything)</p>
  
  <pre><code>foreach (var item in types)
  {
      var ts = item.GetField("DefaultTimeToExpire");
      Type[] typeArguments = item.GetGenericArguments();
      if (ts != null)
      {
          var t = item.MakeGenericType(typeArguments);
          var obj = Activator.CreateInstance(t);
          var timespan = obj.DefaultTimeToExpire;
          subscriberInfos.Add(new Tuple&lt;string, Type, TimeSpan&gt;(item.Name, item, timespan));
      }
  }
  </code></pre>
  
  <p>I am calling GetField to look for Items that have a field "DefaultTimeToExpire" so far this part works well to find the type I need.
  Next I call GetGenericArguments which returns an expected array of the type Arguments. 
  then I call MakeGenericType
  and finally Create instance wich gives me the error message </p>
  
  <p>"Cannot create an instance of BusinessLogic.TestSubscriberXXX`1[Message] because Type.ContainsGenericParameters is true."</p>
  
  <p>This looks like exactly what I am supposed to do.
  Thanks</p>