当前位置: 首页>>代码示例>>C#>>正文


C# ExpressionBuilder类代码示例

本文整理汇总了C#中ExpressionBuilder的典型用法代码示例。如果您正苦于以下问题:C# ExpressionBuilder类的具体用法?C# ExpressionBuilder怎么用?C# ExpressionBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExpressionBuilder类属于命名空间,在下文中一共展示了ExpressionBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Convert

        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.Transform(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.Transform(e => e == info.Parameter ? param : e);
                            path.Expr = path.Expr.Transform(e => e == info.Parameter ? param : e);
                        }
                }

                info.Parameter = param;

                return info;
            }

            return null;
        }
开发者ID:pebezo,项目名称:linq2db,代码行数:30,代码来源:WhereBuilder.cs

示例2: BuildSkip

        static void BuildSkip(ExpressionBuilder builder, IBuildContext sequence, ISqlExpression prevSkipValue, ISqlExpression expr)
        {
            var sql = sequence.SqlQuery;

            builder.SqlProvider.SqlQuery = sql;

            sql.Select.Skip(expr);

            builder.SqlProvider.SqlQuery = sql;

            if (sql.Select.TakeValue != null)
            {
                if (builder.DataContextInfo.SqlProviderFlags.GetIsSkipSupportedFlag(sql) ||
                    !builder.DataContextInfo.SqlProviderFlags.IsTakeSupported)
                    sql.Select.Take(builder.Convert(
                        sequence,
                        new SqlBinaryExpression(typeof(int), sql.Select.TakeValue, "-", sql.Select.SkipValue, Precedence.Additive)));

                if (prevSkipValue != null)
                    sql.Select.Skip(builder.Convert(
                        sequence,
                        new SqlBinaryExpression(typeof(int), prevSkipValue, "+", sql.Select.SkipValue, Precedence.Additive)));
            }

            if (!builder.DataContextInfo.SqlProviderFlags.GetAcceptsTakeAsParameterFlag(sql))
            {
                var p = sql.Select.SkipValue as SqlParameter;

                if (p != null)
                    p.IsQueryParameter = false;
            }
        }
开发者ID:henleygao,项目名称:linq2db,代码行数:32,代码来源:TakeSkipBuilder.cs

示例3: BuildMethodCall

        protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
        {
            var sequence = builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[0]));

            if (sequence.SelectQuery.Select.TakeValue != null || sequence.SelectQuery.Select.SkipValue != null)
                sequence = new SubQueryContext(sequence);

            var lambda  = (LambdaExpression)methodCall.Arguments[1].Unwrap();
            var sparent = sequence.Parent;
            var order   = new ExpressionContext(buildInfo.Parent, sequence, lambda);
            var body    = lambda.Body.Unwrap();
            var sql     = builder.ConvertExpressions(order, body, ConvertFlags.Key);

            builder.ReplaceParent(order, sparent);

            if (!methodCall.Method.Name.StartsWith("Then"))
                sequence.SelectQuery.OrderBy.Items.Clear();

            foreach (var expr in sql)
            {
                var e = builder.ConvertSearchCondition(sequence, expr.Sql);
                sequence.SelectQuery.OrderBy.Expr(e, methodCall.Method.Name.EndsWith("Descending"));
            }

            return sequence;
        }
开发者ID:petedv,项目名称:linq2db,代码行数:26,代码来源:OrderByBuilder.cs

示例4: IsSequence

		public bool IsSequence(ExpressionBuilder builder, BuildInfo buildInfo)
		{
			var expr = (ChangeTypeExpression)buildInfo.Expression;
			var info = new BuildInfo(buildInfo, expr.Expression);

			return GetBuilder(builder, info).IsSequence(builder, info);
		}
开发者ID:Convey-Compliance,项目名称:linq2db,代码行数:7,代码来源:ChangeTypeExpressionBuilder.cs

示例5: BuildMethodCall

        protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
        {
            var sequence = builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[0]));
            var query    = builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[1], new SqlQuery()));
            var except   = query.SqlQuery;

            sequence = new SubQueryContext(sequence);

            var sql = sequence.SqlQuery;

            except.ParentSql = sql;

            if (methodCall.Method.Name == "Except")
                sql.Where.Not.Exists(except);
            else
                sql.Where.Exists(except);

            var keys1 = sequence.ConvertToSql(null, 0, ConvertFlags.Key);
            var keys2 = query.   ConvertToSql(null, 0, ConvertFlags.Key);

            if (keys1.Length != keys2.Length)
                throw new InvalidOperationException();

            for (var i = 0; i < keys1.Length; i++)
            {
                except.Where
                    .Expr(keys1[i].Sql)
                    .Equal
                    .Expr(keys2[i].Sql);
            }

            return sequence;
        }
开发者ID:henleygao,项目名称:linq2db,代码行数:33,代码来源:IntersectBuilder.cs

示例6: StringContainsString

 public void StringContainsString()
 {
     var builder = new ExpressionBuilder<User>();
     var condition = builder.BuildContains("Password", "123");
     var where = builder.Build(condition);
     var results = db.Set<User>().Where(where).ToList();
     Console.WriteLine(results.Count + "条数据");
 }
开发者ID:dusdong,项目名称:BaseComponent,代码行数:8,代码来源:DynamicExpressTest.cs

示例7: NotEqualsTupleTrue_Test

        public void NotEqualsTupleTrue_Test()
        {
            ExpressionBuilder builder = new ExpressionBuilder();
            Expression<Func<bool,bool, bool>> expression = builder.Create<Func<bool,bool, bool>>("A != B");
            Func<bool,bool, bool> func = expression.Compile();

            Assert.IsTrue(func(false, true));
        }
开发者ID:calexconc,项目名称:TextToCalcExpression,代码行数:8,代码来源:ComparisonOperationsTests.cs

示例8: EvaluateBoolValue_Test

        public void EvaluateBoolValue_Test()
        {
            ExpressionBuilder builder = new ExpressionBuilder();
            Expression<Func<bool>> expression = builder.Create<Func<bool>>("false");
            Func<bool> func = expression.Compile();

            Assert.AreEqual(func(), false);
        }
开发者ID:calexconc,项目名称:TextToCalcExpression,代码行数:8,代码来源:EvalTests.cs

示例9: Cos_Test3

        public void Cos_Test3()
        {
            ExpressionBuilder builder = new ExpressionBuilder();
            Expression<Func<double,double>> expression = builder.Create<Func<double, double>>("-COS -A");
            Func<double,double> func = expression.Compile();

            Assert.AreEqual(func(Math.PI), 1);
        }
开发者ID:calexconc,项目名称:TextToCalcExpression,代码行数:8,代码来源:FunctionsTests.cs

示例10: Poli3ArgsPlusConstantPlusParentesisFunction_Test

        public void Poli3ArgsPlusConstantPlusParentesisFunction_Test()
        {
            ExpressionBuilder builder = new ExpressionBuilder();
            Expression<Func<int,int, int,int>> expression = builder.Create<Func<int,int, int, int>>("A * (B+C)+6");
            Func<int,int, int, int> func = expression.Compile();

            Assert.AreEqual(func(16, 2, -2), 6);
        }
开发者ID:calexconc,项目名称:TextToCalcExpression,代码行数:8,代码来源:ArithmeticTests.cs

示例11: EmptyParentesisExpression_Test

        public void EmptyParentesisExpression_Test()
        {
            ExpressionBuilder builder = new ExpressionBuilder();
            Expression<Func<int>> expression = builder.Create<Func<int>>("2+1+()-1");
            Func<int> func = expression.Compile();

            Assert.AreEqual(func(), 0);
        }
开发者ID:calexconc,项目名称:TextToCalcExpression,代码行数:8,代码来源:ParseErrorsTests.cs

示例12: Cos_Test

        public void Cos_Test()
        {
            ExpressionBuilder builder = new ExpressionBuilder();
            Expression<Func<int,int>> expression = builder.Create<Func<int, int>>("COS A");
            Func<int,int> func = expression.Compile();

            Assert.AreEqual(func(0), 1);
        }
开发者ID:calexconc,项目名称:TextToCalcExpression,代码行数:8,代码来源:FunctionsTests.cs

示例13: EmptyExpression_Test

        public void EmptyExpression_Test()
        {
            ExpressionBuilder builder = new ExpressionBuilder();
            Expression<Func<bool>> expression = builder.Create<Func<bool>>("");
            Func<bool> func = expression.Compile();

            Assert.IsTrue(func());
        }
开发者ID:calexconc,项目名称:TextToCalcExpression,代码行数:8,代码来源:ParseErrorsTests.cs

示例14: EvaluateNumericalOperation2_Test

        public void EvaluateNumericalOperation2_Test()
        {
            ExpressionBuilder builder = new ExpressionBuilder();
            Expression<Func<int>> expression = builder.Create<Func<int>>("2^3");
            Func<int> func = expression.Compile();

            Assert.AreEqual(func(), 8);
        }
开发者ID:calexconc,项目名称:TextToCalcExpression,代码行数:8,代码来源:EvalTests.cs

示例15: EvaluateConstantValue_Test

        public void EvaluateConstantValue_Test()
        {
            ExpressionBuilder builder = new ExpressionBuilder();
            Expression<Func<double>> expression = builder.Create<Func<double>>("-PI");
            Func<double> func = expression.Compile();

            Assert.AreEqual(func(), -1*Math.PI);
        }
开发者ID:calexconc,项目名称:TextToCalcExpression,代码行数:8,代码来源:EvalTests.cs


注:本文中的ExpressionBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。