Cast To Interface

前端 未结 2 347
长发绾君心
长发绾君心 2021-01-25 00:08

I am not getting any errors in my code, but my filter object is always null. When I run the debugger the filter object looks just like the sort object, a list with stuff in it.

2条回答
  •  再見小時候
    2021-01-25 00:36

    The list is null because you are trying to cast List into List, but just because FilterDescriptor inherits from IFilterDescriptor doesn't mean that List inherits from List (unless the list is covariant List which it isn't).

    You should do it like this:

    IList filter = request.Filters;
    

    if the interface is fine with that, otherwise you can case the list like that:

    List filter = request.Filters.OfType.ToList();
    

提交回复
热议问题