private object Populate(object instance, PopulateOption populateOption) { if (populateOption != PopulateOption.None) { this.Populate(instance, populateOption == PopulateOption.Deep); } return(instance); }
/// <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="predicate">The predicate.</param> /// <returns>An instance of the specified type.</returns> public static T Any <T>( this IAnonymousData anon, PopulateOption populateOption, Predicate <T> predicate) { Argument.NotNull(anon, nameof(anon)); Argument.NotNull(predicate, nameof(predicate)); return(anon.Any <T>(populateOption, 20, predicate)); }
/// <summary> /// Anies the specified type. /// </summary> /// <param name="anon">The anon.</param> /// <param name="type">The type.</param> /// <param name="populateOption">The populate option.</param> /// <param name="predicate">The predicate.</param> /// <returns>An instance of the specified type.</returns> public static object Any( this IAnonymousData anon, Type type, PopulateOption populateOption, Predicate <object> predicate) { Argument.NotNull(anon, nameof(anon)); Argument.NotNull(type, nameof(type)); Argument.NotNull(predicate, nameof(predicate)); return(anon.Any(type, populateOption, 20, predicate)); }
/// <summary> /// Creates an instance of the specified type of object. /// </summary> /// <param name="type">The type to create.</param> /// <param name="populateOption">The populate option.</param> /// <returns> /// An instance of the specified type. /// </returns> /// <exception cref="AnonymousDataException">The specified type could not be created.</exception> public object Any(Type type, PopulateOption populateOption) { Argument.NotNull(type, nameof(type)); if (type.Is <AnonymousData>() || type.Is <IAnonymousData>()) { return(this); } Factory factory; if (this.factories.TryGetValue(type, out factory) || GlobalFactories.TryGetValue(type, out factory)) { object value; try { value = factory(this); this.Populate(value, populateOption); } catch (Exception e) { throw new AnonymousDataException(type, e); } return(value); } var context = new AnonymousDataContext(this, type); object result; try { if (context.CallNextCustomization(out result)) { return(this.Populate(result, populateOption)); } } catch (Exception e) { throw new AnonymousDataException(type, e); } throw new AnonymousDataException(type); }
/// <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)); }
public object Any(Type type, PopulateOption populateOption) { Argument.NotNull(type, nameof(type)); return(this.factory.Any(type, populateOption)); }