I'm having a custom control that 'can' have a ListCollectionView passed as ItemsSource, which I need the Child-Type of for Reflection Usage.
Now I could find the Type fromthe first element:
Type t = lcv.GetItemAt(0).GetType();
However that wouldn't work, when the Collection was empty.
It also works by calling AddNew()
Object o = lcv.AddNew()
Type t = o.GetType();
But I don't want to call AddNew just to create a dummy object as this causes bugs as site effect.
However if the Method "AddNew()" knows which type of an object to create, there must be a way to find out the actual Child-Type without having to create one.
I've used google, msdn as well as Try & Error and couldn't find how.
Some ideas? Thanks in advance :-)
You can use GetGenericArguments to find the type contained in the collection
var type = lcv.SourceCollection.GetType().GetGenericArguments()[0]