/// <summary> /// Changes the items within a list to populate them with new random values. /// </summary> /// <typeparam name="T">Type of list with items to change.</typeparam> /// <param name="list">List with items to change.</param> /// <param name="allItems">Change all items in list. False changes random items.</param> public static void ChangeListItems<T>(T list, bool allItems) where T : IList { foreach (var item in list) { if (allItems || RandomUtilities.GetRandomBoolean()) { PopulateObjectWithRandomValues(item); } } }
/// <summary> /// Add a random number of new items to a list. /// </summary> /// <typeparam name="T">Type of list.</typeparam> /// <param name="list">List to add items to.</param> public static void AddRandomItemsToList<T>(T list) where T : IList { Type listType = list.GetType().GenericTypeArguments[0]; if ((listType.IsClass || typeof(IList).IsAssignableFrom(listType)) && listType != typeof(string)) { for (int i = 0; i < new Random().Next(5, 20); i++) { list.Add(CreateInstanceWithRandomValues(listType)); } } else { for (int i = 0; i < new Random().Next(5, 20); i++) { list.Add(RandomUtilities.GetRandom(listType)); } } }