Casting an object as an ObservableCollection<object>
<p>I am trying to write a method that gets all of the ObservableCollections in a viewModel and casts each as an <code>ObservableCollection&lt;object&gt;</code>. Using reflection I've been able to get each <code>ObservableCollection&lt;T&gt;</code> as an object, but I'm having difficulties casting this object to an <code>ObservableCollection&lt;object&gt;</code>. Here is my code thus far: </p>

<pre><code>var props = viewModel.GetType().GetProperties();

Type t = viewModel.GetType();

foreach (var prop in props)
{
    if (prop.PropertyType.Name == "ObservableCollection`1")
    {
        Type type = prop.PropertyType;
        var property = (t.GetProperty(prop.Name)).GetValue(viewModel);

        // cast property as an ObservableCollection&lt;object&gt;
    }
}
</code></pre>

<p>Does anyone know how I should proceed?</p>