상속: IExpression
예제 #1
0
        private static string AsName(IExpression expression)
        {
            if (expression is VariableExpression)
            {
                return(((VariableExpression)expression).Name);
            }

            if (expression is DotExpression)
            {
                DotExpression dot = (DotExpression)expression;

                return(AsName(dot.Expression) + "." + dot.Name);
            }

            return(null);
        }
예제 #2
0
        public void EvaluateDotExpressionOnString()
        {
            IExpression expression = new DotExpression(new ConstantExpression("foo"), "Length");

            Assert.AreEqual(3, expression.Evaluate(null));
        }
예제 #3
0
        public void EvaluateDotExpressionOnInteger()
        {
            IExpression expression = new DotExpression(new ConstantExpression(1), "ToString", new List<IExpression>());

            Assert.AreEqual("1", expression.Evaluate(null));
        }
예제 #4
0
        public void EvaluateDotExpressionAsTypeInvocation()
        {
            DotExpression dot = new DotExpression(new DotExpression(new DotExpression(new VariableExpression("System"), "IO"), "File"), "Exists", new IExpression[] { new ConstantExpression("unknown.txt") });

            Assert.IsFalse((bool) dot.Evaluate(new Context()));
        }
예제 #5
0
파일: Parser.cs 프로젝트: ajlopez/DartSharp
        private IExpression ParseDotExpression()
        {
            IExpression expression = this.ParseSimpleExpression();

            if (expression == null)
                return null;

            while (this.TryParseToken(".", TokenType.Separator))
            {
                string name = this.ParseName();
                if (this.TryParseToken("(", TokenType.Separator))
                {
                    expression = new DotExpression(expression, name, this.ParseExpressionList(")"));
                }
                else
                    expression = new DotExpression(expression, name);
            }

            return expression;
        }