コード例 #1
0
 public SelectorMethodOperatorBase(IDictionary <string, ParameterExpression> parameters, IExpressionPart sourceOperand, IExpressionPart selectorBody, string selectorParameterName)
 {
     SourceOperand         = sourceOperand;
     SelectorBody          = selectorBody;
     SelectorParameterName = selectorParameterName;
     Parameters            = parameters;
 }
コード例 #2
0
 public FilterLambdaOperator(IDictionary <string, ParameterExpression> parameters, IExpressionPart filterBody, Type sourceElementType, string parameterName)
 {
     FilterBody        = filterBody;
     SourceElementType = sourceElementType;
     ParameterName     = parameterName;
     Parameters        = parameters;
 }
コード例 #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;
 }
コード例 #5
0
ファイル: Processing.cs プロジェクト: MH1/Kraken.Expressions
 /// <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;
     }));
 }
コード例 #6
0
 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
 );
コード例 #7
0
 public static LambdaExpression GetFilter(this IExpressionPart filterPart, Type sourceType, IDictionary <string, ParameterExpression> parameters, string parameterName)
 => (LambdaExpression) new FilterLambdaOperator
 (
     parameters,
     filterPart,
     sourceType,
     parameterName
 ).Build();
コード例 #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
 );
コード例 #9
0
 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();
コード例 #10
0
ファイル: Processing.cs プロジェクト: MH1/Kraken.Expressions
 /// <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]);
     }
 }
コード例 #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;
        }
コード例 #12
0
ファイル: Processing.cs プロジェクト: MH1/Kraken.Expressions
        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);
        }
コード例 #13
0
 public MinOperator(IExpressionPart sourceOperand) : base(sourceOperand)
 {
 }
コード例 #14
0
 public SkipOperator(IExpressionPart sourceOperand, int count)
 {
     SourceOperand = sourceOperand;
     Count         = count;
 }
コード例 #15
0
 public EqualityBinaryOperatorHandlerBase(IExpressionPart left, IExpressionPart right, FilterFunction @operator) : base(left, right, @operator)
 {
 }
コード例 #16
0
        internal virtual object Compile(IExpressionPart part)
        {
            _aliasMap = part.AliasMap;

            return Compile(part.Expression);
        }
コード例 #17
0
        public static string Compile(IExpressionPart part)
        {
            var item = Instance.Compile(part);
            if (item == null)
            {
                return string.Empty;
            }

            return item.ToString();
        }
コード例 #18
0
 public EqualsBinaryOperator(IExpressionPart left, IExpressionPart right) : base(left, right)
 {
     BinaryOperatorHandler = new EqualsBinaryOperatorHandler(Left, Right, Operator);
 }
コード例 #19
0
 public IndexOfOperator(IExpressionPart sourceOperand, IExpressionPart itemToFind)
 {
     SourceOperand = sourceOperand;
     ItemToFind    = itemToFind;
 }
コード例 #20
0
 public MinOperator(IDictionary <string, ParameterExpression> parameters, IExpressionPart sourceOperand, IExpressionPart selectorBody, string selectorParameterName) : base(parameters, sourceOperand, selectorBody, selectorParameterName)
 {
 }
コード例 #21
0
 public ToUpperOperator(IExpressionPart operand)
 {
     Operand = operand;
 }
コード例 #22
0
 public NotOperator(IExpressionPart operand)
 {
     this.Operand = operand;
 }
コード例 #23
0
 public CeilingOperator(IExpressionPart operand)
 {
     Operand = operand;
 }
コード例 #24
0
 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);
コード例 #25
0
 public ConvertOperator(IExpressionPart sourceOperand, Type type)
 {
     Type          = type;
     SourceOperand = sourceOperand;
 }
コード例 #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
 );
コード例 #27
0
 public static Expression <Func <IQueryable <TModel>, IQueryable <TModel> > > GetQueryFunc(IExpressionPart selectorExpression)
 => (Expression <Func <IQueryable <TModel>, IQueryable <TModel> > >)selectorExpression?.Build();
コード例 #28
0
 public CastOperator(IExpressionPart operand, System.Type type)
 {
     Operand = operand;
     Type    = type;
 }
コード例 #29
0
 public DivideBinaryOperator(IExpressionPart left, IExpressionPart right) : base(left, right)
 {
 }
コード例 #30
0
 public MinuteOperator(IExpressionPart operand)
 {
     Operand = operand;
 }
コード例 #31
0
 public static Expression <Func <TModel, bool> > GetFilter(IExpressionPart filterExpression)
 => (Expression <Func <TModel, bool> >)filterExpression?.Build();
コード例 #32
0
 public HourOperator(IExpressionPart operand)
 {
     Operand = operand;
 }