Parse() public static method

public static Parse ( LinkedList scopes, string originalExpression ) : ExpressionNode
scopes LinkedList
originalExpression string
return Veil.Parser.ExpressionNode
コード例 #1
0
        public void Should_parse_hasitems_expression()
        {
            var model  = new { Items = new[] { 1, 2, 3 } };
            var result = SuperSimpleExpressionParser.Parse(CreateScopes(model.GetType()), "HasItems");

            result.ShouldDeepEqual(Expression.HasItems(Expression.Property(model.GetType(), "Items")));
        }
コード例 #2
0
        public void Should_give_precedence_to_property_over_hasitems()
        {
            var model  = new { Items = new[] { 1, 2, 3 }, HasItems = true };
            var result = SuperSimpleExpressionParser.Parse(CreateScopes(model.GetType()), "HasItems");

            result.ShouldDeepEqual(Expression.Property(model.GetType(), "HasItems"));
        }
コード例 #3
0
        public void Should_parse_current_keyword_as_self_expression()
        {
            var model  = new { };
            var result = SuperSimpleExpressionParser.Parse(CreateScopes(model.GetType()), "Current");

            result.ShouldDeepEqual(Expression.Self(model.GetType()));
        }
コード例 #4
0
        public void Should_parse_model_dot_property_as_proeprty_expression()
        {
            var model  = new { Name = "foo" };
            var result = SuperSimpleExpressionParser.Parse(CreateScopes(model.GetType()), "Model.Name");

            result.ShouldDeepEqual(Expression.Property(model.GetType(), "Name", ExpressionScope.RootModel));
        }
コード例 #5
0
        public void Should_preference_late_binding_over_Has_prefix()
        {
            var model  = new { HasItems = true, Items = new string[0] };
            var result = SuperSimpleExpressionParser.Parse(CreateScopes(typeof(object)), "Model.HasItems");

            result.ShouldDeepEqual(Expression.LateBound("HasItems", true, ExpressionScope.RootModel));
        }
コード例 #6
0
        public void Should_parse_model_keywords_as_self_expression_scoped_to_root()
        {
            var model  = new { };
            var result = SuperSimpleExpressionParser.Parse(CreateScopes(model.GetType()), "Model");

            result.ShouldDeepEqual(Expression.Self(model.GetType(), ExpressionScope.RootModel));
        }
コード例 #7
0
        public void Should_throw_for_invalid_expressions(string expression)
        {
            var model = new { Name = "foo" };

            Assert.Throws <VeilParserException>(() =>
            {
                SuperSimpleExpressionParser.Parse(CreateScopes(model.GetType()), expression);
            });
        }
コード例 #8
0
        public void Should_parse_sub_model_expression_from_current_model()
        {
            var model  = new { User = new { Name = "Bob" } };
            var result = SuperSimpleExpressionParser.Parse(CreateScopes(model.GetType()), "Current.User.Name");

            result.ShouldDeepEqual(Expression.SubModel(
                                       Expression.Property(model.GetType(), "User"),
                                       Expression.Property(model.User.GetType(), "Name")
                                       ));
        }
コード例 #9
0
        public void Should_parse_sub_model_expression_from_root_model()
        {
            var model  = new { User = new { Name = "Bob" } };
            var result = SuperSimpleExpressionParser.Parse(CreateScopes(model.GetType()), "Model.User.Name");

            result.ShouldDeepEqual(SyntaxTreeExpression.SubModel(
                                       SyntaxTreeExpression.Property(model.GetType(), "User", ExpressionScope.RootModel),
                                       SyntaxTreeExpression.Property(model.User.GetType(), "Name")
                                       ));
        }
コード例 #10
0
        public void Should_parse_multiple_sub_model_expressions()
        {
            var model  = new { User = new { Department = new { Company = new { Name = "Foo" } } } };
            var result = SuperSimpleExpressionParser.Parse(CreateScopes(model.GetType()), "Model.User.Department.Company.Name");

            result.ShouldDeepEqual(Expression.SubModel(
                                       Expression.Property(model.GetType(), "User", ExpressionScope.RootModel),
                                       Expression.SubModel(
                                           Expression.Property(model.User.GetType(), "Department"),
                                           Expression.SubModel(
                                               Expression.Property(model.User.Department.GetType(), "Company"),
                                               Expression.Property(model.User.Department.Company.GetType(), "Name")
                                               )
                                           )
                                       ));
        }
コード例 #11
0
        public void Should_parse_as_late_bound_when_model_type_is_not_known <T>(T model)
        {
            var result = SuperSimpleExpressionParser.Parse(CreateScopes(typeof(T)), "Model.Name");

            result.ShouldDeepEqual(Expression.LateBound("Name", true, ExpressionScope.RootModel));
        }
コード例 #12
0
        public void Should_parse_field_references()
        {
            var result = SuperSimpleExpressionParser.Parse(CreateScopes(typeof(ViewModel)), "Model.FieldName");

            result.ShouldDeepEqual(Expression.Field(typeof(ViewModel), "FieldName", ExpressionScope.RootModel));
        }
コード例 #13
0
 public ExpressionNode ParseExpression(string expression)
 {
     return(SuperSimpleExpressionParser.Parse(this.scopeStack, expression));
 }