Why doesn't ObservableCollection implement IList?

1.5k Views Asked by At

I have a Type of {System.Collections.ObjectModel.ObservableCollection} and it implements the following interfaces

enter image description here

This is my code to check if the type implements IList

if (type.IsGenericType && type.GetInterfaces().Contains(typeof(IList<>)))
{
    type = type.GetGenericArguments()[0];
    enclosedType = EnclosedType.List;
}

Why doesn't this work? I feel like I'm missing something obvious.

1

There are 1 best solutions below

0
Jordy Langen On BEST ANSWER

As stated below. It implements IList<TheType> and not IList You need to check the generic type definitions for the interfaces.

Example:

type.GetInterfaces()
    .Where(i => i.IsGenericType)
    .Select(i => i.GetGenericTypeDefinition())
    .Contains(typeof(IList<>));