/// <summary> /// Combines two Validate pipelines, but only if the first pipeline is valid. /// </summary> /// <typeparam name="TI">The type of the object that is passed into the pipeline delegate when invoked.</typeparam> /// <typeparam name="TV">First pipeline: The type of the source object that is the Val of the source IValueAndSupplement interface.</typeparam> /// <typeparam name="TW">Second pipeline: The type of the source object that is the Val of the source IValueAndSupplement interface.</typeparam> /// <typeparam name="TR">The resulting object that is the Supplemented value of the returned ToValueSupplementValue object. The supplemented value implements the IValidatorResults interface with broken validations.</typeparam> /// <typeparam name="TS">The supplemented value of the first pipeline. The supplemented value implements the IValidatorResults interface with broken validations.</typeparam> /// <param name="firstValidatorPipe">The first validate pipelines</param> /// <param name="invokeeSecondPipeLine">Func delegate that returns the second validate pipeline.</param> /// <param name="secondValidatorPipe">Validator type of the resulting pipeline.</param> /// <returns>An object of type ToValueSupplementValue (Func delegate that returns an object that implements the IValueAndSupplement interface when invoked with an object of type TI.</returns> public static Pipe.ToValueSupplementValue <TI, TW, TR> JoinIfValid <TI, TV, TW, TR, TS>( this Pipe.ToValueSupplementValue <TI, TV, TS> firstValidatorPipe, Func <TV, TW> invokeeSecondPipeLine, Pipe.ToValueSupplementValue <TW, TW, TR> secondValidatorPipe) where TI : new() where TV : new() where TW : new() where TR : IValidatorResults, new() where TS : IValidatorResults, new() { TS input = new TS(); Pipe.ToValueSupplementValue <TW, TW, TR> Second() { if (input.Messages.Count == 0) { return(secondValidatorPipe); } return(Pipe.Init(() => new TR(), new Validator <TW, TR>())); } return(firstValidatorPipe.Transform(x => { input = x.SupplementVal; return invokeeSecondPipeLine(x.Val); }, Second, (TS src, TR ret) => ret.Messages.AddRange(src.Messages))); }
/// <summary> /// Combines two Validate pipelines, even if the first pipeline is invalid. /// </summary> /// <typeparam name="TI">The type of the object that is passed into the pipeline delegate when invoked.</typeparam> /// <typeparam name="TV">First pipeline: The type of the source object that is the Val of the source IValueAndSupplement interface.</typeparam> /// <typeparam name="TW">Second pipeline: The type of the source object that is the Val of the source IValueAndSupplement interface.</typeparam> /// <typeparam name="TR">The resulting object that is the Supplemented value of the returned ToValueSupplementValue object. The supplemented value implements the IValidatorResults interface with broken validations.</typeparam> /// <typeparam name="TS">The supplemented value of the first pipeline. The supplemented value implements the IValidatorResults interface with broken validations.</typeparam> /// <param name="firstValidatorPipe">The first validate pipelines</param> /// <param name="invokeeSecondPipeLine">Func delegate that returns the second validate pipeline.</param> /// <param name="secondValidatorPipe">Validator type of the resulting pipeline.</param> /// <returns>An object of type ToValueSupplementValue (Func delegate that returns an object that implements the IValueAndSupplement interface when invoked with an object of type TI.</returns> public static Pipe.ToValueSupplementValue <TI, TW, TR> Join <TI, TV, TW, TR, TS>( this Pipe.ToValueSupplementValue <TI, TV, TS> firstValidatorPipe, TW invokeeSecondPipeLine, Pipe.ToValueSupplementValue <TW, TW, TR> secondValidatorPipe) where TI : new() where TV : new() where TW : new() where TR : IValidatorResults, new() where TS : IValidatorResults, new() { return(firstValidatorPipe.Then((TS _) => invokeeSecondPipeLine, secondValidatorPipe, (src, ret) => ret.Messages.AddRange(src.Messages))); }