示例#1
0
        public object Evaluate(string expression)
        {
            ExpressionNode node = ExpressionParser.Parse(expression, false);

            if (this.Items.Count == 0 || ExpressionNode.GetNodes <AggregateNode>(node).Count == 0)
            {
                return((object)null);
            }
            List <NameNode>  nodes            = ExpressionNode.GetNodes <NameNode>(node);
            StringCollection stringCollection = new StringCollection();

            foreach (NameNode nameNode in nodes)
            {
                if (!stringCollection.Contains(nameNode.Name))
                {
                    stringCollection.Add(nameNode.Name);
                }
            }
            ExpressionContext context = ExpressionContext.GetContext(Thread.CurrentThread.ManagedThreadId);

            context.Clear();
            for (int index = 0; index < stringCollection.Count; ++index)
            {
                if (context.ContainsKey(stringCollection[index]))
                {
                    context[stringCollection[index]] = this.Items[0][stringCollection[index]];
                }
                else
                {
                    context.Add(stringCollection[index], this.Items[0][stringCollection[index]]);
                }
            }
            return(node.Eval((object)new AggregateItems <T>((IEnumerable <T>) this.Items), (object)context));
        }
示例#2
0
 private bool PerformExpressionFilter(TDataItem item)
 {
     if (this.filterContext.Count == 0)
     {
         return(true);
     }
     try
     {
         lock (this.syncobjs)
         {
             int managedThreadId = Thread.CurrentThread.ManagedThreadId;
             ExpressionContext expressionContext = managedThreadId != this.mainThreadId ? ExpressionContext.GetContext(managedThreadId) : ExpressionContext.Context;
             expressionContext.Clear();
             expressionContext.CaseSensitive = this.CaseSensitive;
             for (int index1 = 0; index1 < this.filterContext.Count; ++index1)
             {
                 string index2 = this.filterContext[index1];
                 object obj    = this.GetFieldValue(item, index2);
                 if (obj is Enum)
                 {
                     obj = (object)Convert.ToInt32(obj);
                 }
                 if (expressionContext.ContainsKey(index2))
                 {
                     expressionContext[index2] = obj;
                 }
                 else
                 {
                     expressionContext.Add(index2, obj);
                 }
             }
             object obj1 = (managedThreadId != this.mainThreadId ? this.GetFilterNode(managedThreadId) : this.filterNode).Eval((object)null, (object)expressionContext);
             if (obj1 is bool)
             {
                 return((bool)obj1);
             }
         }
     }
     catch (Exception ex)
     {
         throw new FilterExpressionException("Invalid filter expression.", ex);
     }
     return(false);
 }