Esempio n. 1
0
        internal static void CheckExpressionResult(string exp, string error, object result, string templateName, string lineContent = "", string errorPrefix = "")
        {
            var errorMsg = string.Empty;

            var childErrorMsg = string.Empty;

            if (error != null)
            {
                childErrorMsg = ConcatErrorMsg(childErrorMsg, error);
            }
            else if (result == null)
            {
                childErrorMsg = ConcatErrorMsg(childErrorMsg, TemplateErrors.NullExpression(exp));
            }

            if (!string.IsNullOrWhiteSpace(lineContent))
            {
                errorMsg = ConcatErrorMsg(errorMsg, TemplateErrors.ErrorExpression(lineContent, templateName, errorPrefix));
            }

            throw new Exception(ConcatErrorMsg(childErrorMsg, errorMsg));
        }
Esempio n. 2
0
        internal static void CheckExpressionResult(string exp, string error, object result, string templateName, ParserRuleContext context = null, string errorPrefix = "")
        {
            var errorMsg = string.Empty;

            var childErrorMsg = string.Empty;

            if (error != null)
            {
                childErrorMsg = ConcatErrorMsg(childErrorMsg, error);
            }
            else if (result == null)
            {
                childErrorMsg = ConcatErrorMsg(childErrorMsg, TemplateErrors.NullExpression(exp));
            }

            if (context != null)
            {
                errorMsg = ConcatErrorMsg(errorMsg, TemplateErrors.ErrorExpression(context.GetText(), templateName, errorPrefix));
            }

            throw new Exception(ConcatErrorMsg(childErrorMsg, errorMsg));
        }
Esempio n. 3
0
        private object EvalExpression(string exp, ParserRuleContext context = null, string errorPrefix = "")
        {
            exp = exp.TrimExpression();
            var(result, error) = EvalByAdaptiveExpression(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 += TemplateErrors.NullExpression(exp);
                }

                if (context != null)
                {
                    errorMsg += TemplateErrors.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);
        }