Mercurial > pub > bltoolkit
view Source/Data/Linq/Builder/WhereBuilder.cs @ 3:1ef98bd70424
!bug 100 +3h
Исправление проблемы BLToolkit + mono 3.4
author | cin |
---|---|
date | Fri, 22 Aug 2014 17:34:46 +0400 |
parents | f990fcb411a9 |
children |
line wrap: on
line source
using System; using System.Linq.Expressions; namespace BLToolkit.Data.Linq.Builder { using BLToolkit.Linq; class WhereBuilder : MethodCallBuilder { protected override bool CanBuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo) { return methodCall.IsQueryable("Where"); } protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo) { var sequence = builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[0])); var condition = (LambdaExpression)methodCall.Arguments[1].Unwrap(); var result = builder.BuildWhere(buildInfo.Parent, sequence, condition, true); result.SetAlias(condition.Parameters[0].Name); return result; } protected override SequenceConvertInfo Convert( ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo, ParameterExpression param) { var predicate = (LambdaExpression)methodCall.Arguments[1].Unwrap(); var info = builder.ConvertSequence(new BuildInfo(buildInfo, methodCall.Arguments[0]), predicate.Parameters[0]); if (info != null) { info.Expression = methodCall.Convert(ex => ConvertMethod(methodCall, 0, info, predicate.Parameters[0], ex)); if (param != null) { if (param.Type != info.Parameter.Type) param = Expression.Parameter(info.Parameter.Type, param.Name); if (info.ExpressionsToReplace != null) foreach (var path in info.ExpressionsToReplace) { path.Path = path.Path.Convert(e => e == info.Parameter ? param : e); path.Expr = path.Expr.Convert(e => e == info.Parameter ? param : e); } } info.Parameter = param; return info; } return null; } } }