Exemple #1
0
        internal static Func <YqlExecutionContext, bool> Compile(YamsterModelQuery query)
        {
            var compiler      = new YqlCompiler(query);
            var compiledQuery = compiler.CoerceTo(compiler.CompileNode(query.FilterNode), typeof(bool),
                                                  "Expecting a boolean expression");

            var filterExpression = Expression.Lambda <Func <YqlExecutionContext, bool> >(
                compiledQuery.Expression, compiler.ExecutionContextParameter);

            var compiledFunc = filterExpression.Compile();

            return(compiledFunc);
        }
        protected Expression CompileTargetExpression(YqlCompiler compiler, out YqlCompiledNode[] compiledArgs)
        {
            Type targetType = YamsterModel.GetModelClass(this.TargetObjectType);

            Expression targetExpression;

            if (TargetObject != null)
            {
                var compiledTargetObject = compiler.CompileNode(TargetObject);
                if (compiledTargetObject.Expression.Type != targetType)
                {
                    ReportError("The target object is " + compiledTargetObject.Expression.Type.Name
                                + ", which cannot be converted to " + targetType.Name);
                }
                targetExpression = compiledTargetObject.Expression;
                compiledArgs     = new[] { compiledTargetObject };
            }
            else
            {
                if (compiler.ModelType != TargetObjectType)
                {
                    ReportError("This expression attempts to retrieve a {0} property from the"
                                + " current context item, which is a {1} object",
                                this.TargetObjectType, compiler.ModelType);
                }

                switch (compiler.ModelType)
                {
                case YamsterModelType.Thread:
                    targetExpression = Expression.Property(compiler.ExecutionContextParameter,
                                                           YqlExecutionContext.Info_Thread);
                    break;

                case YamsterModelType.Message:
                    targetExpression = Expression.Property(compiler.ExecutionContextParameter,
                                                           YqlExecutionContext.Info_Message);
                    break;

                default:
                    throw new NotSupportedException();
                }
                compiledArgs = new YqlCompiledNode[0];
            }
            return(targetExpression);
        }