vendredi 6 octobre 2017

Find if class implements IList

So I have a class with two properties

public class MyClass
{

    private List<MyObject> _list1
    Public List<MyObject> List1
    {
     get { return _list1; }
     set { _list1 = value; }
    }

    private ObservableCollection<MyObject> _list2
    Public ObservableCollection<MyObject> List2
    {
     get { return _list2; }
     set { _list2 = value; }
    }

}

And I am trying to get any properties that implement IList<MyObject> I know that List<T> directly implements IList<T> and ObservableCollection<T> implemenets Collection<T> that implements IList<T> so somewhere along the line both properties implement IList<T>

but running the following:

MyClassInstance.GetType().GetTypeInfo().DeclaredProperties.Where(x => x.PropertyType.GetTypeInfo().IsAssignableFrom(typeof(IList<Sub>).GetTypeInfo()).Count();

returns 0 not 2

So what am i doing wrong?





Aucun commentaire:

Enregistrer un commentaire