I have a generic method like the one below. And I check that the incomming parameter is a IList but how do I convert the parameter to a IList?
public T myMethod<T>(T parameter)
{
//check if the parameter is a list
if (parameter IList && parameter.GetType().IsGenericType)
{
//How can I convert my parameter to an IList that supports IEnumerable interface?
// So i can do the following
foreach (var listObject in parameter)
{
// Do stuff
}
}
}
How about
(parameter as IList).I assume you don’t want to just restrict the parameter to an
IListin all cases.