コード例 #1
0
        public override Value Evaluate()
        {
            var   evaluated = expression.Evaluate();
            Value returned;

            if (evaluated is None)
            {
                if (guardBlock.IsSome)
                {
                    returned = ifTrue.Evaluate();
                    result   = ifTrue.ToString();
                    typeName = returned.Type.ToString();
                    return(returned);
                }

                if (ifFalse.IsSome)
                {
                    returned = ifFalse.Value.Evaluate();
                    result   = ifFalse.ToString();
                    typeName = returned.Type.ToString();
                    return(returned);
                }

                return(null);
            }

            //var maybe = evaluated.As<Some>();
            if (evaluated is Some)
            {
                if (ifFalse.IsSome)
                {
                    returned = ifFalse.Value.Evaluate();
                    result   = returned.ToString();
                    typeName = returned.Type.ToString();
                    return(returned);
                }

                return(null);
            }

            //var value = maybe.Value();
            if (guardBlock.IsSome)
            {
                //Regions.Current.SetParameter(fieldName, value);
                if (guardBlock.Value.IsTrue)
                {
                    result   = guardBlock.Value.ToString();
                    typeName = guardBlock.Value.Type.ToString();
                    return(null);
                }

                returned = ifTrue.Evaluate();
                result   = ifTrue.ToString();
                typeName = returned.Type.ToString();
                return(returned);
            }

            using (var popper = new RegionPopper(new Region(), "maybe"))
            {
                popper.Push();
                //Regions.Current.SetParameter(fieldName, value);
                returned = ifTrue.Evaluate();
                result   = ifTrue.ToString();
                typeName = returned.Type.ToString();
            }
            return(returned);
        }
コード例 #2
0
ファイル: Maybe.cs プロジェクト: toddcoder/Orange2
        public override Value Evaluate()
        {
            var   evaluated = expression.Evaluate();
            Value returned;

            switch (evaluated)
            {
            case None when _guardBlock.IsSome:
                returned = ifTrue.Evaluate();
                result   = ifTrue.ToString();
                typeName = returned.Type.ToString();

                return(returned);

            case None when _ifFalse.If(out var ifFalse):
                returned = ifFalse.Evaluate();

                result   = _ifFalse.ToString();
                typeName = returned.Type.ToString();

                return(returned);

            case None:
                return(null);

            case Some when _ifFalse.If(out var ifFalse):
                returned = ifFalse.Evaluate();

                result   = returned.ToString();
                typeName = returned.Type.ToString();

                return(returned);

            case Some:
                return(null);
            }

            if (_guardBlock.If(out var guardBlock))
            {
                if (guardBlock.IsTrue)
                {
                    result   = guardBlock.ToString();
                    typeName = guardBlock.Type.ToString();

                    return(null);
                }

                returned = ifTrue.Evaluate();
                result   = ifTrue.ToString();
                typeName = returned.Type.ToString();
                return(returned);
            }

            using var popper = new RegionPopper(new Region(), "maybe");
            popper.Push();

            returned = ifTrue.Evaluate();
            result   = ifTrue.ToString();
            typeName = returned.Type.ToString();

            return(returned);
        }