How to determine if object is of type IEnumerable
Code:
namespace NS {
class Program {
static IEnumerable GetInts()
Same technique as Marc's answer, but Linqier:
namespace NS
{
class Program
{
static IEnumerable GetInts()
{
yield return 1;
}
static void Main()
{
var i = GetInts();
var type = i.GetType();
var isEnumerableOfT = type.GetInterfaces()
.Any(ti => ti.IsGenericType
&& ti.GetGenericTypeDefinition() == typeof(IEnumerable<>));
Console.WriteLine(isEnumerableOfT);
}
}
}