Esempio n. 1
0
 public SelectorMethodOperatorBase(IDictionary <string, ParameterExpression> parameters, IExpressionPart sourceOperand, IExpressionPart selectorBody, string selectorParameterName)
 {
     SourceOperand         = sourceOperand;
     SelectorBody          = selectorBody;
     SelectorParameterName = selectorParameterName;
     Parameters            = parameters;
 }
 public FilterLambdaOperator(IDictionary <string, ParameterExpression> parameters, IExpressionPart filterBody, Type sourceElementType, string parameterName)
 {
     FilterBody        = filterBody;
     SourceElementType = sourceElementType;
     ParameterName     = parameterName;
     Parameters        = parameters;
 }
Esempio n. 3
0
 public FilterMethodOperatorBase(IDictionary <string, ParameterExpression> parameters, IExpressionPart sourceOperand, IExpressionPart filterBody, string filterParameterName)
 {
     SourceOperand       = sourceOperand;
     FilterBody          = filterBody;
     Parameters          = parameters;
     FilterParameterName = filterParameterName;
 }
 public IEnumerableSelectorLambdaOperator(IDictionary <string, ParameterExpression> parameters, IExpressionPart selector, Type sourceElementType, string parameterName)
 {
     Selector          = selector;
     SourceElementType = sourceElementType;
     ParameterName     = parameterName;
     Parameters        = parameters;
 }
Esempio n. 5
0
 /// <summary>
 /// Compile the single item if it is possible to compile.
 /// It concerns those <see cref="ExpressionPart"/>s items which returns expression in <seealso cref="ExpressionPart.GetExpression(EvaluationContext, string, ref ExpressionData)"/>.
 /// </summary>
 /// <param name="context">The context of evaluation.</param>
 /// <param name="expressionTree">The expression tree.</param>
 protected virtual bool CompileSingleItem(EvaluationContext context, IList <ProcessedItem> expressionTree)
 {
     // compile single item
     return(ReverseLoop(expressionTree, i =>
     {
         ProcessedItem item = expressionTree[i];
         if (item.ItemType != null)
         {
             IExpressionPart obj = GetObject(item.ItemType);
             ExpressionData data = new ExpressionData();
             Expression compiled = obj.GetExpression(context, item.Content, ref data);
             if (compiled != null)
             {
                 ProcessedItem newItem = ProcessedItem.Create(compiled);
                 expressionTree.RemoveAt(i);
                 expressionTree.Insert(i, newItem);
                 return true;
             }
             else if (data.TypeToCast != null)
             {
                 ProcessedItem newItem = ProcessedItem.CreateCast(data.TypeToCast);
                 expressionTree.RemoveAt(i);
                 expressionTree.Insert(i, newItem);
                 return true;
             }
         }
         return false;
     }));
 }
 public static Expression <Func <T, TResult> > GetExpression <T, TResult>(this IExpressionPart filterPart, IDictionary <string, ParameterExpression> parameters, string parameterName)
 => (Expression <Func <T, TResult> >)filterPart.GetExpression
 (
     typeof(T),
     typeof(TResult),
     parameters,
     parameterName
 );
 public static LambdaExpression GetFilter(this IExpressionPart filterPart, Type sourceType, IDictionary <string, ParameterExpression> parameters, string parameterName)
 => (LambdaExpression) new FilterLambdaOperator
 (
     parameters,
     filterPart,
     sourceType,
     parameterName
 ).Build();
Esempio n. 8
0
 private static Task <IEnumerable <dynamic> > Query <TModel, TData>(IContextRepository repository,
                                                                    IExpressionPart queryExpression)
     where TModel : BaseModel
     where TData : BaseData
 => repository.QueryAsync <TModel, TData, IEnumerable <dynamic>, IEnumerable <dynamic> >
 (
     (Expression <Func <IQueryable <TModel>, IEnumerable <dynamic> > >)queryExpression.Build(),
     (SelectExpandDefinition)null
 );
 private async static Task <TModel> QueryEntity <TModel, TData>(IContextRepository repository,
                                                                IExpressionPart filterExpression, SelectExpandDefinition selectExpandDefinition = null)
     where TModel : BaseModel
     where TData : BaseData
 => (
     await repository.GetAsync <TModel, TData>
     (
         (Expression <Func <TModel, bool> >)filterExpression.Build(),
         null,
         selectExpandDefinition
     )
     ).FirstOrDefault();
Esempio n. 10
0
 /// <summary>
 /// Get the <seealso cref="ExpressionPart"/> object instance to parse the expression.
 /// </summary>
 /// <param name="type">The type of the <seealso cref="ExpressionPart"/>.</param>
 /// <returns></returns>
 protected static IExpressionPart GetObject(Type type)
 {
     lock (EvalObjectsLock)
     {
         if (EvalObjects.ContainsKey(type))
         {
             return(EvalObjects[type]);
         }
         IExpressionPart newObj = (IExpressionPart)Activator.CreateInstance(type);
         EvalObjects.Add(type, newObj);
         return(EvalObjects[type]);
     }
 }
Esempio n. 11
0
        public IExpression Add(IExpressionPart expressionPart)
        {
            ExpressionNode node = new ExpressionNode { Current = expressionPart };

            if (head == null)
                head = node;
            else
                tail.Next = node;
            tail = node;

            Count++;

            return this;
        }
Esempio n. 12
0
        internal virtual Expression Parse(EvaluationContext context, ref string code)
        {
            if (code == null)
            {
                throw new ArgumentNullException(nameof(code));
            }
            IList <ProcessedItem> expressionTree = new List <ProcessedItem>();
            IExpressionPart       current        = GetObject <TParserEntry>();

            code = code.TrimStart(context.Whitespaces);
            string source = code;

            while (!string.IsNullOrEmpty(code))
            {
                bool found = false;
                foreach (Type partType in current.ExpectedParts)
                {
                    IExpressionPart newPart = GetObject(partType);
                    string          part    = newPart.Get(context, ref code);
                    if (!string.IsNullOrEmpty(part))
                    {
                        expressionTree.Add(ProcessedItem.Create(partType, part));
                        current = newPart;
                        found   = true;
                        break;
                    }
                }
                if (!found)
                {
                    string dependentObjects = string.Join(", ",
                                                          current.ExpectedParts.Select(o => o.Name)
#if NET35
                                                          .ToArray()
#endif
                                                          );
                    throw new EvaluationException($"Invalid expression, unable to parse.\nCurrent part: {current.GetType().Name}\nFollowing parts: {dependentObjects}\n{code}")
                          {
                              SourceExpression = source, Position = source.Length - code.Length + 1
                          };
                }
                code = code.TrimStart(context.Whitespaces);
            }

            Expression compiled = Compile(context, expressionTree);

            return(compiled);
        }
 public MinOperator(IExpressionPart sourceOperand) : base(sourceOperand)
 {
 }
 public SkipOperator(IExpressionPart sourceOperand, int count)
 {
     SourceOperand = sourceOperand;
     Count         = count;
 }
Esempio n. 15
0
 public EqualityBinaryOperatorHandlerBase(IExpressionPart left, IExpressionPart right, FilterFunction @operator) : base(left, right, @operator)
 {
 }
        internal virtual object Compile(IExpressionPart part)
        {
            _aliasMap = part.AliasMap;

            return Compile(part.Expression);
        }
        public static string Compile(IExpressionPart part)
        {
            var item = Instance.Compile(part);
            if (item == null)
            {
                return string.Empty;
            }

            return item.ToString();
        }
 public EqualsBinaryOperator(IExpressionPart left, IExpressionPart right) : base(left, right)
 {
     BinaryOperatorHandler = new EqualsBinaryOperatorHandler(Left, Right, Operator);
 }
Esempio n. 19
0
 public IndexOfOperator(IExpressionPart sourceOperand, IExpressionPart itemToFind)
 {
     SourceOperand = sourceOperand;
     ItemToFind    = itemToFind;
 }
 public MinOperator(IDictionary <string, ParameterExpression> parameters, IExpressionPart sourceOperand, IExpressionPart selectorBody, string selectorParameterName) : base(parameters, sourceOperand, selectorBody, selectorParameterName)
 {
 }
 public ToUpperOperator(IExpressionPart operand)
 {
     Operand = operand;
 }
 public NotOperator(IExpressionPart operand)
 {
     this.Operand = operand;
 }
 public CeilingOperator(IExpressionPart operand)
 {
     Operand = operand;
 }
 public static Expression <Func <T, bool> > GetFilter <T>(this IExpressionPart filterPart, IDictionary <string, ParameterExpression> parameters, string parameterName)
 => (Expression <Func <T, bool> >)filterPart.GetFilter(typeof(T), parameters, parameterName);
 public ConvertOperator(IExpressionPart sourceOperand, Type type)
 {
     Type          = type;
     SourceOperand = sourceOperand;
 }
Esempio n. 26
0
 private static Task <TModelReturn> Query <TModel, TData, TModelReturn, TDataReturn>(IContextRepository repository,
                                                                                     IExpressionPart queryExpression)
     where TModel : BaseModel
     where TData : BaseData
 => repository.QueryAsync <TModel, TData, TModelReturn, TDataReturn>
 (
     (Expression <Func <IQueryable <TModel>, TModelReturn> >)queryExpression.Build(),
     (SelectExpandDefinition)null
 );
Esempio n. 27
0
 public static Expression <Func <IQueryable <TModel>, IQueryable <TModel> > > GetQueryFunc(IExpressionPart selectorExpression)
 => (Expression <Func <IQueryable <TModel>, IQueryable <TModel> > >)selectorExpression?.Build();
Esempio n. 28
0
 public CastOperator(IExpressionPart operand, System.Type type)
 {
     Operand = operand;
     Type    = type;
 }
Esempio n. 29
0
 public DivideBinaryOperator(IExpressionPart left, IExpressionPart right) : base(left, right)
 {
 }
 public MinuteOperator(IExpressionPart operand)
 {
     Operand = operand;
 }
 public static Expression <Func <TModel, bool> > GetFilter(IExpressionPart filterExpression)
 => (Expression <Func <TModel, bool> >)filterExpression?.Build();
 public HourOperator(IExpressionPart operand)
 {
     Operand = operand;
 }