I have a generic list:
IList<T> myobj = new List<T>();
how to check if myobj is a generic list (aka. IList<T>)?
I’ve tried, with no success:
if(myobj.GetType().IsGenericType && myobj is IList) //second exp is never true
I don’t want to know the Type of T at this moment, i just want to know if myobj is a list.
—EDIT———————
‘myobj’ was being null all the time, this caused it to fail all checks. Sorry, my bad. Turns out the solutions described in my questions (which are similar to some of your answers) works just fine. I haven’t tried the other answers though.
I was doing the following:
PropertyType propInf = ...
var myobj = propInf.GetValue(parentobj,null);//was always null
Have you tried
(myObj is IList):Most of the generic collection interfaces in .NET have non-generic counterparts (for example
IListandIList<T>)http://msdn.microsoft.com/en-us/library/system.collections.ilist.aspx