Subscribing to a ObservableCollection via reflection
Posted
by Julian Lettner
on Stack Overflow
See other posts from Stack Overflow
or by Julian Lettner
Published on 2010-06-17T22:19:56Z
Indexed on
2010/06/17
22:23 UTC
Read the original article
Hit count: 313
reflection
|.net3.5
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.
© Stack Overflow or respective owner