/////// <summary> /////// Returns a random item from the specified <see cref="Array"/>. /////// </summary> /////// <param name="anon">The anonymous data provider to use.</param> /////// <param name="array">The <see cref="Array"/>.</param> /////// <returns>A random item from the collection.</returns> ////public static object AnyItem(this IAnonymousData anon, Array array) ////{ //// var index = anon.AnyInt32(0, array.Length); //// return array.GetValue(index); ////} private static IEnumerable AnyEnumerable(IAnonymousData anon, Type type, int length) { for (int i = 0; i < length; ++i) { yield return(anon.Any(type)); } }
/// <summary> /// Anies the specified predicate. /// </summary> /// <typeparam name="T">The type to create.</typeparam> /// <param name="anon">The anon.</param> /// <param name="predicate">The predicate.</param> /// <returns>An instance of the specified type.</returns> public static T Any <T>( this IAnonymousData anon, Predicate <T> predicate) { Argument.NotNull(anon, nameof(anon)); Argument.NotNull(predicate, nameof(predicate)); return(anon.Any <T>(PopulateOption.None, 20, predicate)); }
/// <summary> /// Anies the specified type. /// </summary> /// <param name="anon">The anon.</param> /// <param name="type">The type.</param> /// <param name="predicate">The predicate.</param> /// <returns>An instance of the specified type.</returns> public static object Any( this IAnonymousData anon, Type type, Predicate <object> predicate) { Argument.NotNull(anon, nameof(anon)); Argument.NotNull(type, nameof(type)); Argument.NotNull(predicate, nameof(predicate)); return(anon.Any(type, PopulateOption.None, 20, predicate)); }
/// <summary> /// Anies the specified retry attempts. /// </summary> /// <typeparam name="T">The type to create.</typeparam> /// <param name="anon">The anon.</param> /// <param name="retryAttempts">The retry attempts.</param> /// <param name="predicate">The predicate.</param> /// <returns>An instance of the specified type.</returns> public static T Any <T>( this IAnonymousData anon, int retryAttempts, Predicate <T> predicate) { Argument.NotNull(anon, nameof(anon)); Argument.NotNull(predicate, nameof(predicate)); Argument.InRange(retryAttempts, 0, int.MaxValue, nameof(retryAttempts)); return(anon.Any <T>(PopulateOption.None, retryAttempts, predicate)); }
/// <summary> /// Anies the specified type. /// </summary> /// <param name="anon">The anon.</param> /// <param name="type">The type.</param> /// <param name="retryAttempts">The retry attempts.</param> /// <param name="predicate">The predicate.</param> /// <returns>An instance of the specified type.</returns> public static object Any( this IAnonymousData anon, Type type, int retryAttempts, Predicate <object> predicate) { Argument.NotNull(anon, nameof(anon)); Argument.NotNull(type, nameof(type)); Argument.NotNull(predicate, nameof(predicate)); Argument.InRange(retryAttempts, 0, int.MaxValue, nameof(retryAttempts)); return(anon.Any(type, PopulateOption.None, retryAttempts, predicate)); }
/// <summary> /// Anies the specified populate option. /// </summary> /// <typeparam name="T">The type to create.</typeparam> /// <param name="anon">The anon.</param> /// <param name="populateOption">The populate option.</param> /// <param name="retryAttempts">The retry attempts.</param> /// <param name="predicate">The predicate.</param> /// <returns>An instance of the specified type.</returns> /// <exception cref="AnonymousDataException">The anonymous data was unable to be created.</exception> public static T Any <T>( this IAnonymousData anon, PopulateOption populateOption, int retryAttempts, Predicate <T> predicate) { Argument.NotNull(anon, nameof(anon)); Argument.NotNull(predicate, nameof(predicate)); Argument.InRange(retryAttempts, 0, int.MaxValue, nameof(retryAttempts)); for (var i = 0; i < retryAttempts; ++i) { var result = anon.Any <T>(populateOption); if (predicate.Invoke(result)) { return(result); } } throw new AnonymousDataException(typeof(T), $"Predicate failed {retryAttempts} times."); }
/// <summary> /// Anies the specified populate option. /// </summary> /// <typeparam name="T">The type of the object to create.</typeparam> /// <param name="anon">The anonymous data provider to use.</param> /// <param name="populateOption">Specifies how to populate the properties.</param> /// <returns>An instance of the specified type.</returns> /// <exception cref="ArgumentNullException"><paramref name="anon"/> is null.</exception> public static T Any <T>(this IAnonymousData anon, PopulateOption populateOption) { Argument.NotNull(anon, nameof(anon)); return((T)anon.Any(typeof(T), populateOption)); }
/// <summary> /// Creates an object of the specified type and optionally populates the properties. /// </summary> /// <param name="anon">The anonymous data provider to use.</param> /// <param name="type">The type to create..</param> /// <returns>An instance of the specified type.</returns> /// <exception cref="ArgumentNullException"><paramref name="anon"/> or <paramref name="type"/> /// is null.</exception> public static object Any(this IAnonymousData anon, Type type) { Argument.NotNull(anon, nameof(anon)); return(anon.Any(type, PopulateOption.None)); }