示例#1
0
        public object Evaluate(ExecutionState state, Token contextToken)
        {
            if (expr is IPropertyEvaluatorExpression)
            {
                if (!((IPropertyEvaluatorExpression)expr).IsValidPropertyName(token.Value))
                {
                    throw new InstructionExecutionException("\"" + token.Value + "\" is not a valid property for this object. (Underlying type: " + expr.GetType().Name + ")", token);
                }
                object x = ((IPropertyEvaluatorExpression)expr).EvaluateProperty(token.Value, token, state);
                if (x != null)
                {
                    if (x.ToString() == VariableExpression.InvalidProperty)
                    {
                        throw new InstructionExecutionException("\"" + token.Value + "\" is not a valid property for this object. (Underlying type: " + expr.GetType().Name + ")", token);
                    }
                }
                return(x);
            }
            object o = expr.Evaluate(state, token);

            if (o is IPropertyEvaluatorExpression)
            {
                return(((IPropertyEvaluatorExpression)o).EvaluateProperty(token.Value, token, state));
            }
            return(SystemTypeEvaluator.EvaluateProperty(o, token.Value, token));
        }
示例#2
0
        public object EvaluateProperty(string propertyName, Token token, ExecutionState state)
        {
            object o = state.HasVariable(variableToken.Value) ? state.GetVariable(variableToken.Value) : null;

            if (o is IPropertyEvaluatorExpression)
            {
                object val = ((IPropertyEvaluatorExpression)o).EvaluateProperty(propertyName, token, state);
                if (val != null)
                {
                    if (val.ToString() == VariableExpression.InvalidProperty)
                    {
                        throw new InstructionExecutionException("\"" + propertyName + "\" is not a valid property of this variable.", token);
                    }
                }
                return(val);
            }
            else
            {
                return(SystemTypeEvaluator.EvaluateProperty(o, propertyName, token));
            }
        }