Ejemplo n.º 1
0
        // Lazy evaluation
        public static FormulaValue Or(EvalVisitor runner, SymbolContext symbolContext, IRContext irContext, FormulaValue[] args)
        {
            foreach (var arg in args)
            {
                var res = runner.EvalArg <BooleanValue>(arg, symbolContext, arg.IRContext);

                if (res.IsValue)
                {
                    var val = res.Value;
                    if (val.Value)
                    {
                        return(new BooleanValue(irContext, true));
                    }
                }
                else if (res.IsError)
                {
                    return(res.Error);
                }
            }
            return(new BooleanValue(irContext, false));
        }
Ejemplo n.º 2
0
        // https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-isblank-isempty
        // Take first non-blank value.
        //
        public static FormulaValue Coalesce(EvalVisitor runner, SymbolContext symbolContext, IRContext irContext, FormulaValue[] args)
        {
            var errors = new List <ErrorValue>();

            foreach (var arg in args)
            {
                var res = runner.EvalArg <ValidFormulaValue>(arg, symbolContext, arg.IRContext);

                if (res.IsValue)
                {
                    var val = res.Value;
                    if (!(val is StringValue str && str.Value == ""))
                    {
                        if (errors.Count == 0)
                        {
                            return(res.ToFormulaValue());
                        }
                        else
                        {
                            return(ErrorValue.Combine(irContext, errors));
                        }
                    }
                }
                if (res.IsError)
                {
                    errors.Add(res.Error);
                }
            }
            if (errors.Count == 0)
            {
                return(new BlankValue(irContext));
            }
            else
            {
                return(ErrorValue.Combine(irContext, errors));
            }
        }