Beispiel #1
0
        public override bool ContinuePipeLineEntry <TB, TA>(
            IValueAndSupplement <TA, TB> pipeInput,
            out PipeBase <TB, TA> wrapInputIntoPipeBase,
            out IPipeOption pipeOption)
        {
            if (pipeInput == null)
            {
                pipeOption            = PipeOption.PipeOptionNone;
                wrapInputIntoPipeBase = new Validator <TB, TA>(pipeOption, ValidationResult.None, null);
                return(false);
            }

            if (pipeInput.GetType() != typeof(Validator <TA, TB>))
            {
                pipeOption            = PipeOption.PipeOptionNone;
                wrapInputIntoPipeBase = new Validator <TB, TA>(new InvalidCastException(), pipeOption, null);
                return(false);
            }

            pipeOption = (IPipeOption)pipeInput;
            var validatorType = ((Validator <TA, TB>)pipeInput).ValidatorType;

            if (validatorType == ValidationResult.Exception)
            {
                wrapInputIntoPipeBase = new Validator <TB, TA>(((Validator <TA, TB>)pipeInput).ExceptionVal, pipeOption, null);
                return(false);
            }

            wrapInputIntoPipeBase = new Validator <TB, TA>(new ValueAndSupplement <TB, TA>(pipeInput.SupplementVal, pipeInput.Val), pipeOption, ExtractMessages(pipeInput.Val, pipeInput.SupplementVal));
            return(true);
        }
Beispiel #2
0
        public override bool ContinuePipeLineEntry <TA, TB>(
            IValueAndSupplement <TA, TB> pipeInput,
            out PipeBase <TA, TB> wrapInputIntoPipeBase,
            out IPipeOption pipeOption)
        {
            if (pipeInput == null)
            {
                pipeOption            = new PipeOption(null, null);
                wrapInputIntoPipeBase = new None <TA, TB>(pipeOption);
                return(false);
            }
            pipeOption = (IPipeOption)pipeInput;

            if (pipeInput.GetType() == typeof(Option <TA, TB>))
            {
                wrapInputIntoPipeBase = new None <TA, TB>(pipeOption);
                return(false);
            }
            if (pipeInput.GetType() == typeof(SomeException <TA, TB>))
            {
                wrapInputIntoPipeBase = new SomeException <TA, TB>(((SomeException <TA, TB>)pipeInput).ExceptionVal, pipeOption);
                return(false);
            }
            if (pipeInput.GetType() == typeof(Validation <TA, TB>))
            {
                wrapInputIntoPipeBase = new Validation <TA, TB>(new ValueAndSupplement <TA, TB>(pipeInput.Val, pipeInput.SupplementVal), pipeOption, ((Validation <TV, TS>)pipeInput).ValidationRet);
                return(false);
            }

            wrapInputIntoPipeBase = new Some <TA, TB>(new ValueAndSupplement <TA, TB>(pipeInput.Val, pipeInput.SupplementVal), pipeOption);
            return(true);
        }
Beispiel #3
0
 public abstract bool ContinuePipeLineEntry <TA, TB, TC, TD>(
     IValueAndSupplement <TA, TB> pipeInput,
     out PipeBase <TC, TD> wrapInputIntoPipeBaseWhenBreak,
     out IPipeOption pipeOption)
     where TA : new()
     where TB : new()
     where TC : new()
     where TD : new();
Beispiel #4
0
        internal Validator(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption, List <string> messages)
        {
            ConditionMet        = pipeOption.ConditionIsMet;
            ExtensionInterfaces = pipeOption.Extensions;
            ValidatorType       = val == null ? ValidationResult.None : ValidationResult.Some;
            var extractedMessages = messages ?? new List <string>();

            if (extractedMessages.Count > 0)
            {
                this.ValidatorType = ValidationResult.SomeInvalid;
            }

            if (val != null)
            {
                GetValue      = val.Val;
                GetSupplement = val.SupplementVal;
            }
        }
Beispiel #5
0
        public override bool ContinuePipeLineEntry <TA, TB, TC, TD>(
            IValueAndSupplement <TA, TB> pipeInput,
            out PipeBase <TC, TD> wrapInputIntoPipeBaseWhenBreak,
            out IPipeOption pipeOption)
        {
            if (pipeInput == null)
            {
                pipeOption = PipeOption.PipeOptionNone;
                wrapInputIntoPipeBaseWhenBreak = new Validator <TC, TD>(pipeOption, ValidationResult.None, null);
                return(false);
            }

            if (pipeInput.GetType() != typeof(Validator <TA, TB>))
            {
                pipeOption = PipeOption.PipeOptionNone;
                wrapInputIntoPipeBaseWhenBreak = new Validator <TC, TD>(new InvalidCastException(), pipeOption, null);
                return(false);
            }

            pipeOption = (IPipeOption)pipeInput;
            var validatorType = ((Validator <TA, TB>)pipeInput).ValidatorType;

            if (validatorType == ValidationResult.None)
            {
                wrapInputIntoPipeBaseWhenBreak = new Validator <TC, TD>(pipeOption, ValidationResult.None, null);
                return(false);
            }

            if (validatorType == ValidationResult.Exception)
            {
                wrapInputIntoPipeBaseWhenBreak = new Validator <TC, TD>(((Validator <TA, TB>)pipeInput).ExceptionVal, pipeOption, null);
                return(false);
            }

            //Because of the out signature we need to instantiate a wrapInputIntoPipeBase, but it will be ignored because we return true, meaning don't break
            wrapInputIntoPipeBaseWhenBreak = new Validator <TC, TD>(new ValueAndSupplement <TC, TD>(default(TC), default(TD)), pipeOption, new List <string>());
            return(true);
        }
Beispiel #6
0
        public override bool ContinuePipeLineEntry <TA, TB, TC, TD>(
            IValueAndSupplement <TA, TB> pipeInput,
            out PipeBase <TC, TD> wrapInputIntoPipeBaseWhenBreak,
            out IPipeOption pipeOption)
        {
            //Determine pipeBaseWhenContinue
            if (pipeInput == null)
            {
                pipeOption = new PipeOption(null, null);
            }
            else
            {
                pipeOption = (IPipeOption)pipeInput;
            }


            //Determine pipeBaseWhenBreak
            if (pipeInput.GetType() == typeof(Option <TA, TB>))
            {
                wrapInputIntoPipeBaseWhenBreak = new None <TC, TD>(pipeOption);
                return(false);
            }
            if (pipeInput.GetType() == typeof(SomeException <TA, TB>))
            {
                wrapInputIntoPipeBaseWhenBreak = new SomeException <TC, TD>(((SomeException <TA, TB>)pipeInput).ExceptionVal, pipeOption);
                return(false);
            }

            if (pipeInput.GetType() == typeof(Validation <TA, TB>))
            {
                wrapInputIntoPipeBaseWhenBreak = new Validation <TC, TD>(new ValueAndSupplement <TC, TD>(default(TC), default(TD)), pipeOption, ((Validation <TC, TD>)pipeInput).ValidationRet);
                return(false);
            }

            //Because of the out signature we need to instantiate a pipeBaseWhenBreak, but it will be ignored because we return true, meaning don't break
            wrapInputIntoPipeBaseWhenBreak = new Some <TC, TD>(new ValueAndSupplement <TC, TD>(default(TC), default(TD)), pipeOption);
            return(true);
        }
Beispiel #7
0
        public override PipeBase <TV, TS> CreateValidation(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption, System.ComponentModel.DataAnnotations.ValidationResult result)
        {
            var msgs = ExtractMessages(GetValue, GetSupplement);

            return(new Validator <TV, TS>(val, pipeOption, msgs));
        }
Beispiel #8
0
        public override PipeBase <TV, TS> CreateSome(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption)
        {
            var msgs = ExtractMessages(GetValue, GetSupplement);

            return(new Validator <TV, TS>(val, pipeOption, msgs));
        }
Beispiel #9
0
 /// <summary>
 /// Wraps the result value of an pipe into a Validator instance.
 /// The ValidationResult property of the Validator class indicates if the pipe was successful, non-successful with broken validations, executed with errors of null values.
 /// </summary>
 /// <typeparam name="TV">The type of the source object that is the Val value of the IValueAndSupplement interface.</typeparam>
 /// <typeparam name="TS">The type of the source object that is the Supplemented value the IValueAndSupplement interface. The supplemented value implements the IValidatorResults interface with broken validations.</typeparam>
 /// <param name="source">The source object.</param>
 /// <returns>A validator instance.</returns>
 public static Validator <TV, TS> Return <TV, TS>(this IValueAndSupplement <TV, TS> source)
     where TV : new()
     where TS : IValidatorResults, new()
 {
     return(new Validator <TV, TS>(source, new PipeOption(true, null), source.SupplementVal.Messages));
 }
Beispiel #10
0
 public static Car AddCarToState(this Car source, IValueAndSupplement <Storage, Car> input)
 {
     input.Val.AddToState(input.SupplementVal);
     return(source);
 }
Beispiel #11
0
 public override PipeBase <TV, TS> CreateSome(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption)
 {
     return(new Some <TV, TS>(val, pipeOption));
 }
Beispiel #12
0
 public abstract PipeBase <TV, TS> CreateSome(
     IValueAndSupplement <TV, TS> val,
     IPipeOption pipeOption);
Beispiel #13
0
 public Validation(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption, ValidationResult validationResult) : base(pipeOption)
 {
     SomeValAndSupplement = val;
     ValidationRet        = validationResult;
 }
Beispiel #14
0
 public Some(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption) : base(pipeOption)
 {
     SomeValAndSupplement = val;
 }
Beispiel #15
0
 public abstract bool ContinuePipeLineEntry <TB, TA>(
     IValueAndSupplement <TA, TB> pipeInput,
     out PipeBase <TB, TA> wrapInputIntoPipeBase,
     out IPipeOption pipeOption)
     where TA : new()
     where TB : new();
Beispiel #16
0
 public abstract PipeBase <TV, TS> CreateValidation(
     IValueAndSupplement <TV, TS> val,
     IPipeOption pipeOption,
     ValidationResult result);
Beispiel #17
0
 public override PipeBase <TV, TS> CreateValidation(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption, ValidationResult result)
 {
     return(new Validation <TV, TS>(val, pipeOption, result));
 }
 public static Storage AddToState(this Storage source, IValueAndSupplement <Car, Storage> input)
 {
     source.AddToState(input.Val);
     return(source);
 }