I have a class (A web control) that has a property of type IEnumerable and would like to work with the parameter using LINQ.
Is there any way to cast / convert / inv
This is years later, but I solved the List problem.
void Method(IEnumerable source)
{
var enumerator = source.GetEnumerator();
if (enumerator.MoveNext())
{
MethodInfo method = typeof(MyClass).GetMethod("Method2");
MethodInfo generic;
Type type = enumerator.Current.GetType();
bool sameType = true;
while (enumerator.MoveNext())
{
if (enumerator.Current.GetType() != type)
{
sameType = false;
break;
}
}
if (sameType)
generic = method.MakeGenericMethod(type);
else
generic = method.MakeGenericMethod(typeof(object));
generic.Invoke(this, new object[] { source });
}
}