public static Array array(Type elementType, IEnumerable enumerable)
{
if (null == enumerable)
{
throw new ArgumentNullException("enumerable");
}
if (null == elementType)
{
throw new ArgumentNullException("elementType");
}
// future optimization, check EnumeratorItemType of enumerable
// and get the fast path whenever possible
List l = null;
if (RuntimeServices.IsPromotableNumeric(Type.GetTypeCode(elementType)))
{
l = new List();
foreach (object item in enumerable)
{
object value = RuntimeServices.CheckNumericPromotion(item).ToType(elementType, null);
l.Add(value);
}
}
else
{
l = new List(enumerable);
}
return l.ToArray(elementType);
}