I am trying to enumerate Object which is actually enumerable, but the type is stored in Type variable
public Type MyListType { get; set; }
public Object MyList { get; set; }
...
foreach (var item in Convert.ChangeType(MyList, MyListType))
{
...
}
This obviously gives an error because ChangeType still returns Object. How can I cast MyList into enumerable type, particularly of MyListType?
Update:
To be more clear, Object is BindingList<T>
type, where T is residing in MyListType.
Jon Skeet :
Well if it's actually enumerable, presumably it implements IEnumerable... so you can just use:\n\nforeach (object item in (IEnumerable) MyList)\n{\n ...\n}\n\n\nYou're not going to have a better compile-time type for item than object anyway...",
2014-08-20T16:48:30