public static bool ItemsToCollection(Type targetType, IEnumerable <object> items, out object result)
{
result = Utils.Instantiate(targetType);
var ilist = result as IList;
if (ilist != null)
{
foreach (var item in items)
{
ilist.Add(item);
}
return(true);
}
var targetTypeInfo = TypeFactory.GetTypeInfo(targetType);
var addMethod = targetTypeInfo.GetMethod("Add");
if (addMethod != null)
{
foreach (var item in items)
{
addMethod.Invoke(result, new object[] { item });
}
return(true);
}
result = null;
return(false);
}