Esempio n. 1
0
        private List <string> EvalExpression(string exp)
        {
            exp = exp.TrimExpression();
            var(result, error) = EvalByExpressionEngine(exp, CurrentTarget().Scope);
            if (error != null)
            {
                throw new Exception(LGErrors.ErrorExpression(exp, error));
            }

            if (result == null)
            {
                throw new Exception(LGErrors.NullExpression(exp));
            }

            if (result is IList &&
                result.GetType().IsGenericType&&
                result.GetType().GetGenericTypeDefinition().IsAssignableFrom(typeof(List <>)))
            {
                return((List <string>)result);
            }

            return(new List <string>()
            {
                result.ToString()
            });
        }
Esempio n. 2
0
        private List <string> EvalExpression(string exp, ParserRuleContext context, string errorPrefix = "")
        {
            exp = exp.TrimExpression();
            var(result, error) = EvalByExpressionEngine(exp, CurrentTarget().Scope);

            if (error != null || (result == null && strictMode))
            {
                var errorMsg = string.Empty;

                var childErrorMsg = string.Empty;
                if (error != null)
                {
                    childErrorMsg += error;
                }
                else if (result == null)
                {
                    childErrorMsg += LGErrors.NullExpression(exp);
                }

                if (context != null)
                {
                    errorMsg += LGErrors.ErrorExpression(context.GetText(), CurrentTarget().TemplateName, errorPrefix);
                }

                if (evaluationTargetStack.Count > 0)
                {
                    evaluationTargetStack.Pop();
                }

                throw new Exception(childErrorMsg + errorMsg);
            }
            else if (result == null && !strictMode)
            {
                result = "null";
            }

            if (result is IList &&
                result.GetType().IsGenericType&&
                result.GetType().GetGenericTypeDefinition().IsAssignableFrom(typeof(List <>)))
            {
                return((List <string>)result);
            }

            return(new List <string>()
            {
                result.ToString()
            });
        }
        private object EvalExpression(string exp)
        {
            exp = exp.TrimExpression();
            var(result, error) = EvalByExpressionEngine(exp, CurrentTarget().Scope);
            if (error != null)
            {
                throw new Exception(LGErrors.ErrorExpression(exp, error));
            }

            if (result == null)
            {
                throw new Exception(LGErrors.NullExpression(exp));
            }

            return(result);
        }
Esempio n. 4
0
        private bool EvalExpressionInCondition(string exp, ParserRuleContext context = null, string errorPrefix = "")
        {
            exp = exp.TrimExpression();
            var(result, error) = EvalByExpressionEngine(exp, CurrentTarget().Scope);

            if (strictMode && (error != null || result == null))
            {
                var errorMsg = string.Empty;

                var childErrorMsg = string.Empty;
                if (error != null)
                {
                    childErrorMsg += error;
                }
                else if (result == null)
                {
                    childErrorMsg += LGErrors.NullExpression(exp);
                }

                if (context != null)
                {
                    errorMsg += LGErrors.ErrorExpression(context.GetText(), CurrentTarget().TemplateName, errorPrefix);
                }

                if (evaluationTargetStack.Count > 0)
                {
                    evaluationTargetStack.Pop();
                }

                throw new Exception(childErrorMsg + errorMsg);
            }
            else if (error != null ||
                     result == null ||
                     (result is bool r1 && r1 == false) ||
                     (result is int r2 && r2 == 0))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        private object EvalExpression(string exp, ParserRuleContext context = null, string errorPrefix = "")
        {
            exp = exp.TrimExpression();
            var(result, error) = EvalByExpressionEngine(exp, CurrentTarget().Scope);

            if (error != null || (result == null && strictMode))
            {
                var errorMsg = string.Empty;

                var childErrorMsg = string.Empty;
                if (error != null)
                {
                    childErrorMsg += error;
                }
                else if (result == null)
                {
                    childErrorMsg += LGErrors.NullExpression(exp);
                }

                if (context != null)
                {
                    errorMsg += LGErrors.ErrorExpression(context.GetText(), CurrentTarget().TemplateName, errorPrefix);
                }

                if (evaluationTargetStack.Count > 0)
                {
                    evaluationTargetStack.Pop();
                }

                throw new Exception(childErrorMsg + errorMsg);
            }
            else if (result == null && !strictMode)
            {
                result = "null";
            }

            return(result);
        }