Exemplo n.º 1
0
        internal Expression BuildGlobalCall(string name, Expression[] args)
        {
            var argTypes   = args.Select(a => a.Type).ToArray();
            var methodInfo = typeof(Globals).GetMethod(name, argTypes);

            if (methodInfo == null)
            {
                throw ODataParser.SyntaxError(this.Parser.Lexer, String.Format("Unknown function: {0} ({1})", name, string.Join(", ", argTypes.Select(x => x.Name))));
            }
            return(Expression.Call(methodInfo, args));
        }
Exemplo n.º 2
0
 private bool ReadString()
 {
     while (true)
     {
         if (!ReadTo("'"))
         {
             throw ODataParser.SyntaxError(this, "Unterminated string");
         }
         if (SrcIndex >= SrcLength || Src[SrcIndex] != Chars.APOS)
         {
             return(true);
         }
         if (!NextChar())
         {
             throw ODataParser.SyntaxError(this, "Unterminated string");
         }
     }
 }
Exemplo n.º 3
0
 public ExpressionBuilder(ODataParser parser)
 {
     this.Parser = parser;
 }
Exemplo n.º 4
0
        internal Expression BuildMemberPath(List <string> steps)
        {
            Type type;
            int  k;

            if (steps[0].Contains('.'))
            {
                type = TypeHandler.GetType(steps[0]);
                if (type == null)
                {
                    throw ODataParser.SyntaxError(this.Parser.Lexer, "Unknown type: " + steps[0]);
                }
                k = 1;
            }
            else
            {
                if (steps.Count == 1 && steps[0] == "ContentType")
                {
                    steps.Add("Name");
                }
                type = typeof(ContentRepository.Content);
                k    = 0;
            }

            Expression expression     = this.x; // Expression.Parameter(type, "x");
            Expression lastExpr       = null;
            Expression lastLastExpr   = null;
            string     lastAspectName = null;

            for (var i = k; i < steps.Count; i++)
            {
                lastLastExpr = lastExpr;
                lastExpr     = expression;

                if (lastAspectName == null)
                {
                    var member = type.GetProperty(steps[i]);
                    expression = member == null?GetDynamicMember(type, steps[i]) : Expression.MakeMemberAccess(member.GetGetMethod().IsStatic ? null : expression, member);

                    if (expression == null)
                    {
                        lastAspectName = steps[i];
                    }
                }
                else
                {
                    var aspect       = Aspect.LoadAspectByName(lastAspectName);
                    var fieldSetting = aspect.FieldSettings.Where(f => f.Name == steps[i]).FirstOrDefault();
                    if (fieldSetting == null)
                    {
                        throw new InvalidOperationException("Field not found: " + lastAspectName + "." + steps[i]);
                    }

                    var fieldName = lastAspectName + "." + steps[i];
                    var fieldType = fieldSetting.FieldDataType;

                    expression     = CreateFieldOfContentAccessExpression(lastLastExpr, fieldName, fieldType);
                    lastAspectName = null;
                }
                type = expression == null ? null : expression.Type;
            }

            if (expression == null)
            {
                throw new InvalidOperationException("Field not found: " + lastAspectName);
            }

            return(expression);
        }