object IAutoGenerator.Generate(AutoGenerateContext context) { // Create the override context and generate an initial instance var overrideContext = new AutoGenerateOverrideContext(context) { Instance = Generator.Generate(context) }; // Then allow each override to alter the intial instance foreach (var generatorOverride in Overrides) { generatorOverride.Generate(overrideContext); } return(overrideContext.Instance); }
object IAutoGenerator.Generate(AutoGenerateContext context) { var overrideContext = new AutoGenerateOverrideContext(context); foreach (var generatorOverride in Overrides) { // Check if an initialized instance is needed if (generatorOverride.Preinitialize && overrideContext.Instance == null) { overrideContext.Instance = Generator.Generate(context); } // Let each override apply updates to the instance generatorOverride.Generate(overrideContext); } return(overrideContext.Instance); }
public override void Generate(AutoGenerateOverrideContext context) { context.Instance = Generator.Invoke(context); }
/// <summary> /// Populates the provided instance with generated values. /// </summary> /// <typeparam name="TType">The type of instance to populate.</typeparam> /// <param name="context">The <see cref="AutoGenerateOverrideContext"/> instance for the current generate request.</param> /// <param name="instance">The instance to populate.</param> public static void Populate <TType>(this AutoGenerateOverrideContext context, TType instance) { context?.GenerateContext.Populate(instance); }
/// <summary> /// Generates a collection of unique instances of type <typeparamref name="TType"/>. /// </summary> /// <typeparam name="TType">The instance type to generate.</typeparam> /// <param name="context">The <see cref="AutoGenerateOverrideContext"/> instance for the current generate request.</param> /// <param name="count">The number of instances to generate.</param> /// <returns>The generated collection of unique instances.</returns> public static List <TType> GenerateUniqueMany <TType>(this AutoGenerateOverrideContext context, int?count = null) { return(context?.GenerateContext.GenerateUniqueMany <TType>(count) ?? new List <TType>()); }
/// <summary> /// Generates an instance of type <typeparamref name="TType"/>. /// </summary> /// <typeparam name="TType">The instance type to generate.</typeparam> /// <param name="context">The <see cref="AutoGenerateOverrideContext"/> instance for the current generate request.</param> /// <returns>The generated instance.</returns> public static TType Generate <TType>(this AutoGenerateOverrideContext context) { return(context == null ? default : context.GenerateContext.Generate <TType>()); }