Subscribing to a ObservableCollection via reflection
- by Julian Lettner
How can I subscribe to a ObservableCollection<??> without knowing the element type of the collection? Is there a way to do this without too many 'magic strings'?
This is a question for the .NET version 3.5. I think 4.0 would make my life much easier, right?
Type type = collection.GetType();
if(type.IsGenericType
&& type.GetGenericTypeDefinition() == typeof(ObservableCollection<>))
{
// I cannot cast the collection here
ObservableCollection<object> x = collection;
}
Thanks for your time.