public static bool Parse(SyntaxContext context, int position) { var list = context.list; var offset = 0; var index = position; var count = 0; var isMissed = false; while (PropertyParser.Parse(context, index)) { ; } while (IndexParser.Parse(context, index)) { ; } if (!list[index].isLeftValue) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsOperator(list[index], ",")) { isMissed = true; context.isMissed = true; } else { // ignored } offset += 1; index = position + offset; if (isMissed) { offset -= 1; } context.Insert(position, ExpressionCreator.CreateLeftEx(list, position, offset)); context.Remove(position + 1, offset); if (isMissed) { return(false); } return(true); }
public static IQueryable GetQueryableByData(IData data, IQueryable sourceQueryable, bool ignoreVersioning) { LambdaExpression whereLambdaExpression = GetWhereLambdaExpression(data, ignoreVersioning); if (sourceQueryable == null) { sourceQueryable = DataFacade.GetData(data.DataSourceId.InterfaceType); } Expression whereExpression = ExpressionCreator.Where(sourceQueryable.Expression, whereLambdaExpression); IQueryable newQueryable = sourceQueryable.Provider.CreateQuery(whereExpression); return(newQueryable); }
/// <exclude /> public static IData GetMetaData(Guid pageId, Guid pageVersionId, string definitionName, Type metaDataType) { Verify.ArgumentNotNull(definitionName, nameof(definitionName)); Verify.ArgumentNotNull(metaDataType, nameof(metaDataType)); //TODO: Consider caching here var parameterExpression = Expression.Parameter(metaDataType); var lambdaExpression = Expression.Lambda( Expression.And( Expression.And( Expression.Equal( Expression.Property( parameterExpression, GetDefinitionPageReferencePropertyInfo(metaDataType) ), Expression.Constant(pageId, typeof(Guid)) ), Expression.Equal( Expression.Property( parameterExpression, GetDefinitionPageReferencePropertyVersionInfo(metaDataType) ), Expression.Constant(pageVersionId, typeof(Guid)) ) ), Expression.Equal( Expression.Property( parameterExpression, GetDefinitionNamePropertyInfo(metaDataType) ), Expression.Constant(definitionName, typeof(string)) )), parameterExpression ); using (var conn = new DataConnection()) { conn.DisableServices(); var whereExpression = ExpressionCreator.Where(DataFacade.GetData(metaDataType).Expression, lambdaExpression); IEnumerable <IData> dataset = ExpressionHelper.GetCastedObjects <IData>(metaDataType, whereExpression); return(dataset.SingleOrDefaultOrException("There're multiple meta data on a page. Page '{0}', definition name '{1}', meta type '{2}'", pageId, definitionName, metaDataType.FullName)); } }
private List <object> GetQueryResult(Type dataType, string idPropertyName, object value) { ParameterExpression parameter = Expression.Parameter(dataType, "parameter"); Expression body = Expression.Equal(Expression.Property(parameter, idPropertyName), Expression.Constant(value)); LambdaExpression lambda = Expression.Lambda(body, parameter); MethodInfo getDataMethod = DataFacade.GetGetDataMethodInfo(dataType); IQueryable queryable = (IQueryable)getDataMethod.Invoke(null, new object[] { true, null }); Expression whereExpression = ExpressionCreator.Where(queryable.Expression, lambda); IEnumerable enumerable = (IEnumerable)queryable.Provider.CreateQuery(whereExpression); return(enumerable.ToListOfObjects()); }
public static bool Parse(SyntaxContext context, int position) { var list = context.list; var offset = 0; var index = position; var count = 0; var isMissed = false; if (list[index].type == Expression.Type.KVList2) { return(false); } count = 0; while (true) { while (KV2Parser.Parse(context, index)) { ; } if (context.isMissed) { context.isMissed = false; offset += 1; index = position + offset; count += 1; break; } if (list[index].type != Expression.Type.KV2) { break; } else { // ignored } offset += 1; index = position + offset; count += 1; } if (count == 0) { return(false); } context.Insert(position, ExpressionCreator.CreateKVList2(list, position, offset)); context.Remove(position + 1, offset); return(true); }
public static bool Parse(SyntaxContext context, int position) { var list = context.list; var offset = 0; var index = position; var count = 0; var isMissed = false; if (!ParserHelper.IsOperator(list[index], "{")) { return(false); } else { // ignored } offset += 1; index = position + offset; while (RightList1Parser.Parse(context, index)) { ; } if (list[index].type != Expression.Type.RightList1) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsOperator(list[index], "}")) { return(false); } else { // ignored } offset += 1; index = position + offset; context.Insert(position, ExpressionCreator.CreateList(list, position, offset)); context.Remove(position + 1, offset); return(true); }
} // Optional public override Expression CreateOrderByExpression(Expression sourceExpression, ParameterExpression parameterExpression, bool first) { Expression fieldExpression = ExpressionHelper.CreatePropertyExpression(this.OwnerNode.InterfaceType, this.PropertyInfo.DeclaringType, this.FieldName, parameterExpression); LambdaExpression lambdaExpression = Expression.Lambda(fieldExpression, parameterExpression); if (first) { return(this.Direction == "ascending" ? ExpressionCreator.OrderBy(sourceExpression, lambdaExpression) : ExpressionCreator.OrderByDescending(sourceExpression, lambdaExpression)); } return(this.Direction == "ascending" ? ExpressionCreator.ThenBy(sourceExpression, lambdaExpression) : ExpressionCreator.ThenByDescending(sourceExpression, lambdaExpression)); }
public static bool Parse(SyntaxContext context, int position) { var list = context.list; var offset = 0; var index = position; var count = 0; var isMissed = false; if (!ParserHelper.IsKeyword(list[index], "do")) { return(false); } else { // ignored } offset += 1; index = position + offset; while (ModuleParser.Parse(context, index)) { ; } if (list[index].type != Expression.Type.Module) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsKeyword(list[index], "end")) { return(false); } else { // ignored } offset += 1; index = position + offset; context.Insert(position, ExpressionCreator.CreateDo(list, position, offset)); context.Remove(position + 1, offset); return(true); }
/// <summary> /// 商品分页列表 /// </summary> /// <param name="search"></param> /// <returns></returns> public async Task <PageModelDto <ProductDto> > GetPagedAsync(ProductSearchPagedDto search) { var whereCondition = ExpressionCreator .New <Product>() .AndIf(search.Id > 0, x => x.Id == search.Id); var total = await _productRepo.CountAsync(whereCondition); if (total == 0) { return(new PageModelDto <ProductDto>(search)); } var entities = await _productRepo .Where(whereCondition) .OrderByDescending(x => x.Id) .Skip(search.SkipRows()) .Take(search.PageSize) .ToListAsync(); var productDtos = Mapper.Map <List <ProductDto> >(entities); if (productDtos.IsNotNullOrEmpty()) { //调用maint微服务获取字典,组合商品状态信息 var restRpcResult = await _maintRestClient.GetDictAsync(RpcConsts.ProdunctStatusId); if (restRpcResult.IsSuccessStatusCode) { var dict = restRpcResult.Content; if (dict is not null && dict.Children.IsNotNullOrEmpty()) { productDtos.ForEach(x => { x.StatusDescription = dict.Children.FirstOrDefault(d => d.Value == x.StatusCode.ToString())?.Name; }); } } } return(new PageModelDto <ProductDto>(search, productDtos, total)); }
public static bool Parse(SyntaxContext context, int position) { var list = context.list; var offset = 0; var index = position; var count = 0; var isMissed = false; if (list[index].type != Expression.Type.Word) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsOperator(list[index], ",")) { isMissed = true; context.isMissed = true; } else { // ignored } offset += 1; index = position + offset; if (isMissed) { offset -= 1; } context.Insert(position, ExpressionCreator.CreateWordEx(list, position, offset)); context.Remove(position + 1, offset); if (isMissed) { return(false); } return(true); }
public static bool Parse(SyntaxContext context, int position) { var list = context.list; var offset = 0; var index = position; var count = 0; var isMissed = false; if (!ParserHelper.IsKeyword(list[index], "break")) { return(false); } else { // ignored } offset += 1; index = position + offset; context.Insert(position, ExpressionCreator.CreateBreak(list, position, offset)); context.Remove(position + 1, offset); return(true); }
/// <exclude /> public static IData GetMetaData(Guid pageId, string definitionName, Type metaDataType) { //TODO: Consider caching here ParameterExpression parameterExpression = Expression.Parameter(metaDataType); LambdaExpression lambdaExpression = Expression.Lambda( Expression.And( Expression.Equal( Expression.Property( parameterExpression, PageMetaDataFacade.GetDefinitionNamePropertyInfo(metaDataType) ), Expression.Constant( definitionName, typeof(string) ) ), Expression.Equal( Expression.Property( parameterExpression, GetDefinitionPageReferencePropertyInfo(metaDataType) ), Expression.Constant( pageId, typeof(Guid) ) ) ), parameterExpression ); Expression whereExpression = ExpressionCreator.Where(DataFacade.GetData(metaDataType).Expression, lambdaExpression); IEnumerable <IData> dataset = ExpressionHelper.GetCastedObjects <IData>(metaDataType, whereExpression); return(dataset.SingleOrDefaultOrException("There're multiple meta data on a page. Page '{0}', definition name '{1}', meta type '{2}'", pageId, definitionName, metaDataType.FullName)); }
public async Task <PageModelDto <RoleDto> > GetPagedAsync(RolePagedSearchDto search) { var whereExpression = ExpressionCreator .New <SysRole>() .AndIf(search.RoleName.IsNotNullOrWhiteSpace(), x => x.Name.Contains(search.RoleName)); var total = await _roleRepository.CountAsync(whereExpression); if (total == 0) { return(new PageModelDto <RoleDto>(search)); } var entities = await _roleRepository .Where(whereExpression) .OrderByDescending(x => x.Id) .Skip(search.SkipRows()) .Take(search.PageSize) .ToListAsync(); var dtos = Mapper.Map <List <RoleDto> >(entities); return(new PageModelDto <RoleDto>(search, dtos, total)); }
public static Expression <Func <T, bool> > ToLambdaExpression <T>(FilterGroup filterGroup) where T : class { if (filterGroup == null) { return(arg => true); } if (filterGroup.Groups == null && filterGroup.Rules == null) { return(arg => true); } if (filterGroup.Groups != null && (filterGroup.Groups.Count == 0 && filterGroup.Rules.Count == 0)) { return(arg => true); } //构建 c=>Body中的c ParameterExpression param = ExpressionCreator <T> .CreateParameterExpression("c"); //构建c=>Body中的Body var body = CreateExpressions <T>(param, filterGroup); //将二者拼为c=>Body var expression = Expression.Lambda <Func <T, bool> >(body, param); return(expression); }
public static bool Parse(SyntaxContext context, int position) { var list = context.list; var offset = 0; var index = position; var count = 0; var isMissed = false; if (!ParserHelper.IsKeyword(list[index], "for")) { return(false); } else { // ignored } offset += 1; index = position + offset; if (list[index].type != Expression.Type.Word) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsOperator(list[index], "=")) { return(false); } else { // ignored } offset += 1; index = position + offset; while (FunctionAParser.Parse(context, index)) { ; } while (ParenParser.Parse(context, index)) { ; } while (TableIParser.Parse(context, index)) { ; } while (TableSParser.Parse(context, index)) { ; } while (ListParser.Parse(context, index)) { ; } while (PropertyParser.Parse(context, index)) { ; } while (IndexParser.Parse(context, index)) { ; } while (CallParser.Parse(context, index)) { ; } while (NotParser.Parse(context, index)) { ; } while (LengthParser.Parse(context, index)) { ; } while (NegateParser.Parse(context, index)) { ; } while (PowerParser.Parse(context, index)) { ; } while (MultiplyParser.Parse(context, index)) { ; } while (DivisionParser.Parse(context, index)) { ; } while (ModParser.Parse(context, index)) { ; } while (AddParser.Parse(context, index)) { ; } while (SubtractParser.Parse(context, index)) { ; } while (ConcatParser.Parse(context, index)) { ; } while (LessParser.Parse(context, index)) { ; } while (GreaterParser.Parse(context, index)) { ; } while (LessEqualParser.Parse(context, index)) { ; } while (GreaterEqualParser.Parse(context, index)) { ; } while (EqualParser.Parse(context, index)) { ; } while (NotEqualParser.Parse(context, index)) { ; } while (AndParser.Parse(context, index)) { ; } while (OrParser.Parse(context, index)) { ; } if (!list[index].isRightValue) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsOperator(list[index], ",")) { return(false); } else { // ignored } offset += 1; index = position + offset; while (FunctionAParser.Parse(context, index)) { ; } while (ParenParser.Parse(context, index)) { ; } while (TableIParser.Parse(context, index)) { ; } while (TableSParser.Parse(context, index)) { ; } while (ListParser.Parse(context, index)) { ; } while (PropertyParser.Parse(context, index)) { ; } while (IndexParser.Parse(context, index)) { ; } while (CallParser.Parse(context, index)) { ; } while (NotParser.Parse(context, index)) { ; } while (LengthParser.Parse(context, index)) { ; } while (NegateParser.Parse(context, index)) { ; } while (PowerParser.Parse(context, index)) { ; } while (MultiplyParser.Parse(context, index)) { ; } while (DivisionParser.Parse(context, index)) { ; } while (ModParser.Parse(context, index)) { ; } while (AddParser.Parse(context, index)) { ; } while (SubtractParser.Parse(context, index)) { ; } while (ConcatParser.Parse(context, index)) { ; } while (LessParser.Parse(context, index)) { ; } while (GreaterParser.Parse(context, index)) { ; } while (LessEqualParser.Parse(context, index)) { ; } while (GreaterEqualParser.Parse(context, index)) { ; } while (EqualParser.Parse(context, index)) { ; } while (NotEqualParser.Parse(context, index)) { ; } while (AndParser.Parse(context, index)) { ; } while (OrParser.Parse(context, index)) { ; } if (!list[index].isRightValue) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsKeyword(list[index], "do")) { return(false); } else { // ignored } offset += 1; index = position + offset; while (ModuleParser.Parse(context, index)) { ; } if (list[index].type != Expression.Type.Module) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsKeyword(list[index], "end")) { return(false); } else { // ignored } offset += 1; index = position + offset; context.Insert(position, ExpressionCreator.CreateFor(list, position, offset)); context.Remove(position + 1, offset); return(true); }
public static bool Parse(SyntaxContext context, int position) { var list = context.list; var offset = 0; var index = position; var count = 0; var isMissed = false; while (ParenParser.Parse(context, index)) { ; } while (TableIParser.Parse(context, index)) { ; } while (TableSParser.Parse(context, index)) { ; } while (ListParser.Parse(context, index)) { ; } while (PropertyParser.Parse(context, index)) { ; } while (IndexParser.Parse(context, index)) { ; } if (!list[index].isRightValue) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsOperator(list[index], "(")) { return(false); } else { // ignored } offset += 1; index = position + offset; while (RightList1Parser.Parse(context, index)) { ; } if (list[index].type != Expression.Type.RightList1) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsOperator(list[index], ")")) { return(false); } else { // ignored } offset += 1; index = position + offset; context.Insert(position, ExpressionCreator.CreateCall(list, position, offset)); context.Remove(position + 1, offset); return(true); }
private static Expression CreateExpression <T>(ParameterExpression param, FilterRule filterRule) where T : class { return(ExpressionCreator <T> .CreateExpression(param, filterRule.Field, filterRule.Value, filterRule.OperatorType)); }
public void CreatePropertyExpressionTest() { Assert.AreEqual("c.Name", Util.ExpressionCreator <Human> .CreatePropertyExpression(ExpressionCreator <Human> .CreateParameterExpression("c"), "Name").ToString()); }
public static bool Parse(SyntaxContext context, int position) { var list = context.list; var offset = 0; var index = position; var count = 0; var isMissed = false; while (ParenParser.Parse(context, index)) { ; } while (TableIParser.Parse(context, index)) { ; } while (TableSParser.Parse(context, index)) { ; } while (ListParser.Parse(context, index)) { ; } while (PropertyParser.Parse(context, index)) { ; } while (IndexParser.Parse(context, index)) { ; } while (CallParser.Parse(context, index)) { ; } while (NotParser.Parse(context, index)) { ; } while (LengthParser.Parse(context, index)) { ; } while (NegateParser.Parse(context, index)) { ; } while (PowerParser.Parse(context, index)) { ; } while (MultiplyParser.Parse(context, index)) { ; } while (DivisionParser.Parse(context, index)) { ; } while (ModParser.Parse(context, index)) { ; } while (AddParser.Parse(context, index)) { ; } while (SubtractParser.Parse(context, index)) { ; } if (!list[index].isRightValue) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsOperator(list[index], "<")) { return(false); } else { // ignored } offset += 1; index = position + offset; while (ParenParser.Parse(context, index)) { ; } while (TableIParser.Parse(context, index)) { ; } while (TableSParser.Parse(context, index)) { ; } while (ListParser.Parse(context, index)) { ; } while (PropertyParser.Parse(context, index)) { ; } while (IndexParser.Parse(context, index)) { ; } while (CallParser.Parse(context, index)) { ; } while (NotParser.Parse(context, index)) { ; } while (LengthParser.Parse(context, index)) { ; } while (NegateParser.Parse(context, index)) { ; } while (PowerParser.Parse(context, index)) { ; } while (MultiplyParser.Parse(context, index)) { ; } while (DivisionParser.Parse(context, index)) { ; } while (ModParser.Parse(context, index)) { ; } while (AddParser.Parse(context, index)) { ; } while (SubtractParser.Parse(context, index)) { ; } if (!list[index].isRightValue) { return(false); } else { // ignored } offset += 1; index = position + offset; context.Insert(position, ExpressionCreator.CreateLess(list, position, offset)); context.Remove(position + 1, offset); return(true); }
public static bool Parse(SyntaxContext context, int position) { var list = context.list; var offset = 0; var index = position; var count = 0; var isMissed = false; count = 0; while (true) { while (ReturnParser.Parse(context, index)) { ; } while (BreakParser.Parse(context, index)) { ; } while (DoParser.Parse(context, index)) { ; } while (WhileParser.Parse(context, index)) { ; } while (ForNParser.Parse(context, index)) { ; } while (ForParser.Parse(context, index)) { ; } while (ForEachParser.Parse(context, index)) { ; } while (FunctionNParser.Parse(context, index)) { ; } while (FunctionSParser.Parse(context, index)) { ; } while (IfParser.Parse(context, index)) { ; } while (IfElseParser.Parse(context, index)) { ; } while (DefineNParser.Parse(context, index)) { ; } while (CallParser.Parse(context, index)) { ; } while (BindParser.Parse(context, index)) { ; } while (BindNParser.Parse(context, index)) { ; } if (context.isMissed) { context.isMissed = false; offset += 1; index = position + offset; count += 1; break; } if (!list[index].isStatement) { break; } else { // ignored } offset += 1; index = position + offset; count += 1; } if (count == 0) { return(false); } context.Insert(position, ExpressionCreator.CreateModule(list, position, offset)); context.Remove(position + 1, offset); return(true); }