title: Get type of items in ObservableCollection
body: <p>I have a view (consists of a listview) that is binded to some observable collection. In other words I have:</p>
  
  <pre><code>var someCollection = new ObservableCollection&lt;ClassFoo&gt;();
  // initialize someCollection
  
  ListView someView = new ListView();
  someView.DataContext = someCollection;
  someView.ItemsSource = someCollection;
  </code></pre>
  
  <p>Note:</p>
  
  <ul>
  <li><code>someView</code> is located on <strong>Project1.dll</strong> and <code>someCollection</code> on <strong>Project2.dll</strong></li>
  <li><strong>Project2.dll</strong> has a reference to <strong>Project1.dll</strong> AND <strong>Project1.dll</strong> DOES NOT have a reference to <strong>Project2.dll</strong></li>
  </ul>
  
  <p>Therefore on my view I have a reference to someCollection of type <code>ObservableCollection&lt;object&gt;</code> because I will get a compilation error if it where to be of its actual type <code>ObservableCollection&lt;ClassFoo&gt;</code> because I would have to add a reference to Project2.dll.</p>
  
  <p>For some reason I cannot add that reference and I my boss wants me to create commands etc...</p>
  
  <hr>
  
  <p>The last part just explains why I want to do this but in short I am looking for:</p>
  
  <pre><code>  ObservableCollection&lt;object&gt; myUnknownObservableCollection = someReference;
    // I know that someReferce is of type ObservableCollection&lt;ClassFoo&gt;
    var x = myUnknownObservableCollection.GetType().GetTypeOfItems.....
  </code></pre>
  
  <p>at the end I will like x to be equal to <code>typeof(ClassFoo)</code> how can I do that with reflection given that someReference is of type <code>ObservableCollection&lt;ClassFoo&gt;</code>?</p>
  
  <hr>
  
  <h2>Edit</h2>
  
  <p>I got a solution!! Here it is:</p>
  
  <pre><code>    class Person 
      {
          public string Name { get { return "Antonio"; } }
      }
  
      .. 
  
      // view code:
  
      IEnumerable&lt;object&gt; uncknownObject;
  
      // view model does this:
      uncknownObject = new ObservableCollection&lt;Person&gt;( );
  
      // continuation of view code:
  
      var observCol = uncknownObject.GetType( );
  
      var x = ( ( dynamic )observCol ).GenericTypeArguments[ 0 ]; 
  
      var instance = ( Person )Activator.CreateInstance( x );
  
      Console.WriteLine( instance.Name ); // Print Antonio!!!
  </code></pre>
  
  <p>It will be nice to be able to do it without the dynamic data type though</p>
  
  <hr>
  
  <h2>Edit 2</h2>
  
  <p><a href="https://stackoverflow.com/questions/14639987/why-reflection-does-not-find-property"><strong>Here is a solution running .net 4.0 without using the dynamic type</strong></a></p>