Esempio n. 1
0
        private static string EvalExpression(ExpressionParser parser, TemplateToken token, TemplateParserContext context)
        {
            char q = token.TokenId == TokenID.ExpressionNew ? '`' : ':';

            int quoteIdx = token.Text.LastIndexOf(q);

            string expr = quoteIdx >= 0 ? token.Text.Substring(0, quoteIdx).Trim() : token.Text;

            IValueWithType result = parser.Evaluate(expr, context, token.TokenPosition);

            if (token.TokenType == TemplateTokenType.Statement)
            {
                return("");
            }

            if (result.Value is Control)
            {
                return(context.View.ParseTranslations(((Control)result.Value).Render(context.View)));
            }

            string fmt = quoteIdx >= 0 ? token.Text.Substring(quoteIdx + 1).Trim() : null;

            if (fmt != null)
            {
                return(String.Format(WebAppConfig.FormatProvider, "{0:" + fmt + "}", result.Value));
            }
            else if (result.Value is string)
            {
                return((string)result.Value);
            }
            else
            {
                return(result.Value == null ? "" : Convert.ToString(result.Value, WebAppConfig.FormatProvider));
            }
        }
Esempio n. 2
0
        public object Evaluate(string s, out Type type, IParserContext context, TokenPosition tokenPosition)
        {
            IValueWithType value = ParseWithContext(s, context, tokenPosition).Evaluate();

            type = value.Type;

            return(value.Value);
        }
Esempio n. 3
0
        public object Evaluate(string s, out Type type)
        {
            IValueWithType value = ParseWithContext(s).Evaluate();

            type = value.Type;

            return(value.Value);
        }
Esempio n. 4
0
 public void Set(string name, IValueWithType data)
 {
     Set(name, data.Value, data.Type);
 }
Esempio n. 5
0
 public void SetLocal(string name, IValueWithType data)
 {
     this.SetLocal(name, data.Value, data.Type);
 }