示例#1
0
        internal static Function SeekFunction(string name, Expression[] arguments, bool seekInsideObservable = false)
        {
            var qualifiedName = string.Format("{0}({1})", name, arguments.Count());

            // TODO: Handle missing function events
            var function = ExpressionsHelper.functions.Where(f => f.FunctionName.Equals(qualifiedName)
                        && arguments.Select(a =>
                        {
                            var type = a.Type.GetFirstObservableGenericType();

                            if (type == null || seekInsideObservable == false)
                            {
                                return a.Type;
                            }

                            return type;

                        })
                                    .SequenceEqual(f.Parameters
                                                        .Select(p => p.Type))).FirstOrDefault();

            return function;
        }
 private static void ExpectArgsCount(int count, Expression[] args, string method)
 {
     if (args.Count() != count)
     throw new EqlCompilerException($"Method '{method}' expects {count} argument(s) but {args.Count()} were supplied");
 }
 private static void ExpectArgsCountBetween(int low, int high, Expression[] args, string method)
 {
     if (args.Count() < low || args.Count() > high)
     throw new EqlCompilerException($"Method '{method}' expects {low}-{high} argument(s) but {args.Count()} were supplied");
 }
        private static Expression MakeOptionalFilterArgumentCall(Expression context, Expression argContext, string methodName, Expression[] args, string actualMethodName)
        {
            ExpectArgsCountBetween(0, 1, args, methodName);

              var allArgs = new List<Expression> { context };
              if (args.Count() == 1) {
            var predicate = args.First();
            ExpectArgTypeToBe(predicate.Type, typeof(bool), methodName);
            allArgs.Add(Expression.Lambda(predicate, argContext as ParameterExpression));
              }

              return ExpressionUtil.MakeExpressionCall(new []{typeof(Queryable), typeof(Enumerable)}, actualMethodName, new Type[] {argContext.Type}, allArgs.ToArray());
        }