tags:

views:

37

answers:

3

Hello,

I am having a UserControl with an ItemsSource that allows only objects, that can be enumerated (implement IEnumerable) and where I can add/delete items. How can I test the latter?

+2  A: 

Check the IsReadOnly property (by casting to IList or ICollection<T>)

SLaks
Nice edit... :P
Johann Blais
A: 

Check for an implementation of the ICollection-interface, instead of IEnumerable. Usually any collection class that has collection manipulation possibilities, implements this interface, or a child.

Joachim VR
+1  A: 

You can check that the object is of type ICollection (generic) or IList (non-generic) and that their IsReadOnly property is not set to True

Johann Blais
@Johann Why check IList if it implements anyway ICollection. Why no straight check if it is of type ICollection?
msfanboy
`IList` does not implement `ICollection<T>`.
SLaks
@SLaks Haha your right! its ICollection...
msfanboy