Exemplo n.º 1
0
        public void Invoke_False_False()
        {
            var expression = new IIf
            {
                Predicate = Constant.Create(nameof(IIf), false),
                True      = Constant.Create(nameof(IIf), "foo"),
                False     = Constant.Create(nameof(IIf), "bar")
            };

            Assert.That.ExpressionsEqual(nameof(IIf), "bar", expression);
        }
Exemplo n.º 2
0
    private static IEnumerable <string> GenerateIf(IIf @if, string contentOfFunctionName, int level, AstModel parent)
    {
        if (VERBOSE)
        {
            yield return("\r\n//<if />\r\n");
        }


        var conditionBlock = @if.ConditionBlock;
        var thenBlock      = @if.ThenBlock;
        var elseBlock      = @if.ElseBlock;

        yield return("((");

        foreach (var conditionCode in GenerateExpression(conditionBlock, contentOfFunctionName, level))
        {
            yield return(conditionCode);
        }
        yield return(") ? function(){\r\n");

        yield return("return ");

        foreach (var thenCode in GenerateExpression(thenBlock, contentOfFunctionName, level + 1))
        {
            yield return(thenCode);
        }
        if (thenBlock.InnerExpr.__type != TYPE_CONSECUTOR)
        {
            yield return(";");
        }
        yield return("\r\n} : function(){\r\n");

        yield return("return ");

        foreach (var elseCode in GenerateExpression(elseBlock, contentOfFunctionName, level + 1))
        {
            yield return(elseCode);
        }
        if (elseBlock.InnerExpr.__type != TYPE_CONSECUTOR)
        {
            yield return(";");
        }
        yield return("\r\n})()\r\n");
    }
Exemplo n.º 3
0
        private IContainer DoIf(IIf tag, IContainer parent, XmlNode node, IValueStack stack)
        {
            bool value = stack.BooleanExpression(tag.Test);

            if (value)
            {
                ProcessChildren(parent, node, stack);
            }
            else
            {
                XmlNode ifNode = node.NextSibling;
                if (ifNode != null && !(ifNode is XmlComment))
                {
                    Type t = TypeFromNode(ifNode);
                    if (t.GetInterfaces().Contains(typeof(IElse)))
                    {
                        ProcessChildren(parent, ifNode, stack);
                    }
                }
            }

            return(parent);
        }
Exemplo n.º 4
0
        public DefaultIfEvaluator(IIf @if)
        {
            _if = @if ?? throw new ArgumentNullException(nameof(@if));

            Infra.NotNull(@if.Condition);

            var currentCondition = @if.Condition.As <IBooleanEvaluator>();
            var currentActions   = ImmutableArray.CreateBuilder <IExecEvaluator>();
            var branchesBuilder  = ImmutableArray.CreateBuilder <(IBooleanEvaluator?Condition, ImmutableArray <IExecEvaluator> Actions)>();

            foreach (var op in @if.Action)
            {
                switch (op)
                {
                case IElseIf elseIf:
                    branchesBuilder.Add((currentCondition, currentActions.ToImmutable()));
                    Infra.NotNull(elseIf.Condition);
                    currentCondition = elseIf.Condition.As <IBooleanEvaluator>();
                    currentActions.Clear();
                    break;

                case IElse:
                    branchesBuilder.Add((currentCondition, currentActions.ToImmutable()));
                    currentCondition = default !;
                    currentActions.Clear();
                    break;

                default:
                    currentActions.Add(op.As <IExecEvaluator>());
                    break;
                }
            }

            branchesBuilder.Add((currentCondition, currentActions.ToImmutable()));

            Branches = branchesBuilder.ToImmutable();
        }
Exemplo n.º 5
0
        private IContainer DoIf(IIf tag, IContainer parent, XmlNode node, IValueStack stack)
        {
            bool value = stack.BooleanExpression(tag.Test);

            if (value)
                ProcessChildren(parent, node, stack);
            else
            {
                XmlNode ifNode = node.NextSibling;
                if (ifNode != null && !(ifNode is XmlComment))
                {
                    Type t = TypeFromNode(ifNode);
                    if (t.GetInterfaces().Contains(typeof(IElse)))
                        ProcessChildren(parent, ifNode, stack);
                }
            }

            return parent;
        }
Exemplo n.º 6
0
 public IfNode(DocumentIdNode documentIdNode, IIf @if) : base(documentIdNode, @if) => _if = @if;