Exemple #1
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);
        }
Exemple #2
0
 public abstract PipeBase <TI, TA> WrapPipeLineResult <TI, TA>(
     Func <TA> init,
     TI value,
     PipeOption pipeOption,
     bool isInit = false)
     where TI : new()
     where TA : new();
Exemple #3
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);
        }
Exemple #4
0
        public override PipeBase <TI, TA> WrapPipeLineResult <TI, TA>(Func <TA> init, TI value, Piping.PipeOption pipeOption, bool isInit = false)
        {
            try
            {
                TA nwevalue = init();
                if (isInit && value.Equals(nwevalue))
                {
                    return(new Validator <TI, TA>(new InvalidOperationException("The Init function must create a new instance of an object"), pipeOption, null));
                }

                ExecuteExtensions(pipeOption, value);
                ExecuteExtensions(pipeOption, nwevalue);

                if (nwevalue == null)
                {
                    return(new Validator <TI, TA>(PipeOption.PipeOptionNone, ValidationResult.None, null));
                }

                var msgs = ExtractMessages(value, nwevalue);
                return(new Validator <TI, TA>(new ValueAndSupplement <TI, TA>(value, nwevalue), pipeOption, msgs));
            }
            catch (Exception ex1)
            {
                return(new Validator <TI, TA>(ex1, PipeOption.PipeOptionNone, null));
            }
        }
Exemple #5
0
        public override PipeBase <TI, TA> WrapPipeLineResult <TI, TA>(Func <TA> init, TI value, PipeOption pipeOption, bool isInit = false)
        {
            TA nwevalue = default(TA);

            try
            {
                nwevalue = init();
                if (isInit && value.Equals(nwevalue))
                {
                    return(new SomeException <TI, TA>(new InvalidOperationException("The Init function must create a new instance of an object"), pipeOption));
                }
                ExecuteExtensions(pipeOption, value);
                ExecuteExtensions(pipeOption, nwevalue);
            }
            catch (Exception ex)
            {
                return(new SomeException <TI, TA>(ex, pipeOption));
            }
            if (nwevalue == null)
            {
                return(new None <TI, TA>(pipeOption));
            }
            return(new Some <TI, TA>(new ValueAndSupplement <TI, TA>(value, nwevalue), pipeOption));
        }