//Make an enumerable of type enumerableType and fill it with items. private object MakeEnumerable(Type enumerableType, List <object> items) { if (enumerableType.IsGenericType && TypesUtil.GenericTypeIsAssignableFrom(enumerableType, typeof(ICollection <>))) { return(MakeListOfType(TypesUtil.GetGenericArgumentForBaseType(enumerableType, typeof(ICollection <>)), items)); } else if (enumerableType.IsArray) { var list = MakeListOfType(enumerableType.GetElementType(), items); return(list.GetType().GetMethod("ToArray").Invoke(list, null)); } else { throw new NotSupportedException("The collection of type " + enumerableType.ToString() + " cannot be bound to the context."); } }