J. Jones <jj@networld.com> wrote:[color=blue]
> Suppose the following:
>
> class MyContainer : System.Collections.CollectionBase
> {
> //...
> }
>
> (where CollectionBase implements IList, ICollection)
>
> How do I determine if a type (such as MyContainer) derives from IList?
>
> System.Type type = typeof(MyContainer);
>
> type is IList -> false
>
> type.IsSubclassOf(typeof(IList)) -> false
>
> type.IsAssignableFrom(typeof(IList)) -> false
>
> etc., all tests return false.
>
> So, what I need is a way to determine if a particular type derives from IList,
> no matter how far up the hierarchy it is.[/color]
You're using IsAssignableFrom the wrong way round - it's very easy to
do, and I always have to look up the documentation to check it.
Basically, you want
typeof(IList).IsAssignableFrom(type)
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too