I am creating a control that receive in datasource a DataSet or List
How i convert a IEnumerable to List in a CreateChildControls event?
protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
{
if (dataSource is System.Data.DataSet)
{
}
else if(dataSource is IList)
{
}
}
Usually one would use the
IEnumerable<T>.ToList()extensionmethod from Linq but in your case you can not use it (right away) because you have the non-genericIEnumerableinterface. Sou you will have to cast it first (also using Linq):No matter what you original collection actually ist, this will always succeed.