mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	# 完善 表达式拼接方法,从 T1-T5;#256
This commit is contained in:
		@@ -110,13 +110,6 @@
 | 
				
			|||||||
            清空状态数据
 | 
					            清空状态数据
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
 | 
					 | 
				
			||||||
            <summary>
 | 
					 | 
				
			||||||
            根据 lambda 条件删除数据
 | 
					 | 
				
			||||||
            </summary>
 | 
					 | 
				
			||||||
            <param name="predicate"></param>
 | 
					 | 
				
			||||||
            <returns></returns>
 | 
					 | 
				
			||||||
        </member>
 | 
					 | 
				
			||||||
        <member name="M:FreeSql.DbSet`1.Add(`0)">
 | 
					        <member name="M:FreeSql.DbSet`1.Add(`0)">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            添加
 | 
					            添加
 | 
				
			||||||
@@ -211,15 +204,6 @@
 | 
				
			|||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
            <returns></returns>
 | 
					            <returns></returns>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="M:FreeSql.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
 | 
					 | 
				
			||||||
            <summary>
 | 
					 | 
				
			||||||
            批量注入 Repository,可以参考代码自行调整
 | 
					 | 
				
			||||||
            </summary>
 | 
					 | 
				
			||||||
            <param name="services"></param>
 | 
					 | 
				
			||||||
            <param name="globalDataFilter"></param>
 | 
					 | 
				
			||||||
            <param name="assemblies"></param>
 | 
					 | 
				
			||||||
            <returns></returns>
 | 
					 | 
				
			||||||
        </member>
 | 
					 | 
				
			||||||
        <member name="M:FreeSql.IBaseRepository.AsType(System.Type)">
 | 
					        <member name="M:FreeSql.IBaseRepository.AsType(System.Type)">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            动态Type,在使用 Repository<object> 后使用本方法,指定实体类型
 | 
					            动态Type,在使用 Repository<object> 后使用本方法,指定实体类型
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,29 +12,36 @@ namespace FreeSql.Tests.Extensions
 | 
				
			|||||||
        public void And()
 | 
					        public void And()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Expression<Func<testExpAddOr, bool>> where = a => a.id == Guid.Empty;
 | 
					            Expression<Func<testExpAddOr, bool>> where = a => a.id == Guid.Empty;
 | 
				
			||||||
 | 
					 | 
				
			||||||
            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000' AND a.\"num\" > 0)", g.sqlite.Select<testExpAddOr>().Where(where.And(b => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000' AND a.\"num\" > 0)", g.sqlite.Select<testExpAddOr>().Where(where.And(b => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.And(false, b => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.And(false, b => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000' AND a.\"num\" = 1 AND a.\"num\" = 2)", g.sqlite.Select<testExpAddOr>().Where(where.And(b => b.num == 1).And(b => b.num == 2)).ToSql().Replace("\r\n", ""));
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000' AND a.\"num\" = 1 AND a.\"num\" = 2)", g.sqlite.Select<testExpAddOr>().Where(where.And(b => b.num == 1).And(b => b.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.And(false, b => b.num == 1).And(false, c => c.num == 2)).ToSql().Replace("\r\n", ""));
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.And(false, b => b.num == 1).And(false, c => c.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            where = null;
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"num\" > 0)", g.sqlite.Select<testExpAddOr>().Where(where.And(b => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a", g.sqlite.Select<testExpAddOr>().Where(where.And(false, b => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"num\" = 1 AND a.\"num\" = 2)", g.sqlite.Select<testExpAddOr>().Where(where.And(b => b.num == 1).And(b => b.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a", g.sqlite.Select<testExpAddOr>().Where(where.And(false, b => b.num == 1).And(false, c => c.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void Or()
 | 
					        public void Or()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Expression<Func<testExpAddOr, bool>> where = a => a.id == Guid.Empty;
 | 
					            Expression<Func<testExpAddOr, bool>> where = a => a.id == Guid.Empty;
 | 
				
			||||||
 | 
					 | 
				
			||||||
            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE ((a.\"id\" = '00000000-0000-0000-0000-000000000000' OR a.\"num\" > 0))", g.sqlite.Select<testExpAddOr>().Where(where.Or(b => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE ((a.\"id\" = '00000000-0000-0000-0000-000000000000' OR a.\"num\" > 0))", g.sqlite.Select<testExpAddOr>().Where(where.Or(b => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.Or(false, b => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.Or(false, b => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (((a.\"id\" = '00000000-0000-0000-0000-000000000000' OR a.\"num\" = 1) OR a.\"num\" = 2))", g.sqlite.Select<testExpAddOr>().Where(where.Or(b => b.num == 1).Or(b => b.num == 2)).ToSql().Replace("\r\n", ""));
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (((a.\"id\" = '00000000-0000-0000-0000-000000000000' OR a.\"num\" = 1) OR a.\"num\" = 2))", g.sqlite.Select<testExpAddOr>().Where(where.Or(b => b.num == 1).Or(b => b.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.Or(false, b => b.num == 1).Or(false, c => c.num == 2)).ToSql().Replace("\r\n", ""));
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.Or(false, b => b.num == 1).Or(false, c => c.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            where = null;
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"num\" > 0)", g.sqlite.Select<testExpAddOr>().Where(where.Or(b => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a", g.sqlite.Select<testExpAddOr>().Where(where.Or(false, b => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE ((a.\"num\" = 1 OR a.\"num\" = 2))", g.sqlite.Select<testExpAddOr>().Where(where.Or(b => b.num == 1).Or(b => b.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a", g.sqlite.Select<testExpAddOr>().Where(where.Or(false, b => b.num == 1).Or(false, c => c.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void Not()
 | 
					        public void Not()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Expression<Func<testExpAddOr, bool>> where = a => a.id == Guid.Empty;
 | 
					            Expression<Func<testExpAddOr, bool>> where = a => a.id == Guid.Empty;
 | 
				
			||||||
 | 
					 | 
				
			||||||
            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (not(a.\"id\" = '00000000-0000-0000-0000-000000000000'))", g.sqlite.Select<testExpAddOr>().Where(where.Not()).ToSql().Replace("\r\n", ""));
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (not(a.\"id\" = '00000000-0000-0000-0000-000000000000'))", g.sqlite.Select<testExpAddOr>().Where(where.Not()).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.Not(false)).ToSql().Replace("\r\n", ""));
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.Not(false)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -45,5 +52,49 @@ namespace FreeSql.Tests.Extensions
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            public int num { get; set; }
 | 
					            public int num { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        class testExpAddOr2
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            public Guid id { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            public int num { get; set; }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Fact]
 | 
				
			||||||
 | 
					        public void And2()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            Expression<Func<testExpAddOr, testExpAddOr2, bool>> where = (a, b) => a.id == b.id;
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE (a.\"id\" = b.\"id\" AND b.\"num\" > 0)", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.And((a, b) => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE (a.\"id\" = b.\"id\")", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.And(false, (a, b) => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE (a.\"id\" = b.\"id\" AND b.\"num\" = 1 AND b.\"num\" = 2)", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.And((a, b) => b.num == 1).And((a, b) => b.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE (a.\"id\" = b.\"id\")", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.And(false, (a, b) => b.num == 1).And(false, (a, c) => c.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            where = null;
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE (b.\"num\" > 0)", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.And((a, b) => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.And(false, (a, b) => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE (b.\"num\" = 1 AND b.\"num\" = 2)", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.And((a, b) => b.num == 1).And((a, b) => b.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.And(false, (a, b) => b.num == 1).And(false, (a, c) => c.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        [Fact]
 | 
				
			||||||
 | 
					        public void Or2()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            Expression<Func<testExpAddOr, testExpAddOr2, bool>> where = (a, b) => a.id == b.id;
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE ((a.\"id\" = b.\"id\" OR b.\"num\" > 0))", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.Or((a, b) => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE (a.\"id\" = b.\"id\")", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.Or(false, (a, b) => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE (((a.\"id\" = b.\"id\" OR b.\"num\" = 1) OR b.\"num\" = 2))", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.Or((a, b) => b.num == 1).Or((a, b) => b.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE (a.\"id\" = b.\"id\")", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.Or(false, (a, b) => b.num == 1).Or(false, (a, c) => c.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            where = null;
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE (b.\"num\" > 0)", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.Or((a, b) => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.Or(false, (a, b) => b.num > 0)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE ((b.\"num\" = 1 OR b.\"num\" = 2))", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.Or((a, b) => b.num == 1).Or((a, b) => b.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.Or(false, (a, b) => b.num == 1).Or(false, (a, c) => c.num == 2)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        [Fact]
 | 
				
			||||||
 | 
					        public void Not2()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            Expression<Func<testExpAddOr, testExpAddOr2, bool>> where = (a, b) => a.id == b.id;
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE (not(a.\"id\" = b.\"id\"))", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.Not()).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					            Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a, \"testExpAddOr2\" b WHERE (a.\"id\" = b.\"id\")", g.sqlite.Select<testExpAddOr, testExpAddOr2>().Where(where.Not(false)).ToSql().Replace("\r\n", ""));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,79 +14,219 @@ namespace System.Linq.Expressions
 | 
				
			|||||||
    public static partial class LambadaExpressionExtensions
 | 
					    public static partial class LambadaExpressionExtensions
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        static LambdaExpression InternalAndOrExpression(bool condition, LambdaExpression exp1, LambdaExpression exp2, bool isAndAlso)
 | 
				
			||||||
        /// 使用 and 拼接两个 lambda 表达式
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        /// <returns></returns>
 | 
					 | 
				
			||||||
        public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> exp1, Expression<Func<T, bool>> exp2) => And(exp1, true, exp2);
 | 
					 | 
				
			||||||
        /// <summary>
 | 
					 | 
				
			||||||
        /// 使用 and 拼接两个 lambda 表达式
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        /// <typeparam name="T"></typeparam>
 | 
					 | 
				
			||||||
        /// <param name="exp1"></param>
 | 
					 | 
				
			||||||
        /// <param name="condition">true 时生效</param>
 | 
					 | 
				
			||||||
        /// <param name="exp2"></param>
 | 
					 | 
				
			||||||
        /// <returns></returns>
 | 
					 | 
				
			||||||
        public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> exp1, bool condition, Expression<Func<T, bool>> exp2)
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (condition == false) return exp1;
 | 
					            if (condition == false) return exp1;
 | 
				
			||||||
            if (exp1 == null) return exp2;
 | 
					            if (exp1 == null) return exp2;
 | 
				
			||||||
            if (exp2 == null) return exp1;
 | 
					            if (exp2 == null) return exp1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            ParameterExpression newParameter = Expression.Parameter(typeof(T), "c");
 | 
					            var newParameters = exp1.Parameters.Select((a, b) => Expression.Parameter(a.Type, $"new{b}")).ToArray();
 | 
				
			||||||
            NewExpressionVisitor visitor = new NewExpressionVisitor(newParameter, exp2.Parameters.FirstOrDefault());
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var left = visitor.Replace(exp1.Body);
 | 
					            var left = new NewExpressionVisitor(newParameters, exp2.Parameters.ToArray()).Replace(exp1.Body);
 | 
				
			||||||
            var right = visitor.Replace(exp2.Body);
 | 
					            var right = new NewExpressionVisitor(newParameters, exp2.Parameters.ToArray()).Replace(exp2.Body);
 | 
				
			||||||
            var body = Expression.AndAlso(left, right);
 | 
					            var body = isAndAlso ? Expression.AndAlso(left, right) : Expression.OrElse(left, right);
 | 
				
			||||||
            return Expression.Lambda<Func<T, bool>>(body, newParameter);
 | 
					            return Expression.Lambda(exp1.Type, body, newParameters);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        static LambdaExpression InternalNotExpression(bool condition, LambdaExpression exp)
 | 
				
			||||||
        /// <summary>
 | 
					 | 
				
			||||||
        /// 使用 or 拼接两个 lambda 表达式
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        /// <returns></returns>
 | 
					 | 
				
			||||||
        public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> exp1, Expression<Func<T, bool>> exp2) => Or(exp1, true, exp2);
 | 
					 | 
				
			||||||
        /// <summary>
 | 
					 | 
				
			||||||
        /// 使用 or 拼接两个 lambda 表达式
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        /// <typeparam name="T"></typeparam>
 | 
					 | 
				
			||||||
        /// <param name="exp1"></param>
 | 
					 | 
				
			||||||
        /// <param name="condition">true 时生效</param>
 | 
					 | 
				
			||||||
        /// <param name="exp2"></param>
 | 
					 | 
				
			||||||
        /// <returns></returns>
 | 
					 | 
				
			||||||
        public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> exp1, bool condition, Expression<Func<T, bool>> exp2)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            if (condition == false) return exp1;
 | 
					 | 
				
			||||||
            if (exp1 == null) return exp2;
 | 
					 | 
				
			||||||
            if (exp2 == null) return exp1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            ParameterExpression newParameter = Expression.Parameter(typeof(T), "c");
 | 
					 | 
				
			||||||
            NewExpressionVisitor visitor = new NewExpressionVisitor(newParameter, exp2.Parameters.FirstOrDefault());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            var left = visitor.Replace(exp1.Body);
 | 
					 | 
				
			||||||
            var right = visitor.Replace(exp2.Body);
 | 
					 | 
				
			||||||
            var body = Expression.OrElse(left, right);
 | 
					 | 
				
			||||||
            return Expression.Lambda<Func<T, bool>>(body, newParameter);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        /// <summary>
 | 
					 | 
				
			||||||
        /// 将 lambda 表达式取反
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        /// <typeparam name="T"></typeparam>
 | 
					 | 
				
			||||||
        /// <param name="exp"></param>
 | 
					 | 
				
			||||||
        /// <param name="condition">true 时生效</param>
 | 
					 | 
				
			||||||
        /// <returns></returns>
 | 
					 | 
				
			||||||
        public static Expression<Func<T, bool>> Not<T>(this Expression<Func<T, bool>> exp, bool condition = true)
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (condition == false) return exp;
 | 
					            if (condition == false) return exp;
 | 
				
			||||||
            if (exp == null) return null;
 | 
					            if (exp == null) return null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var candidateExpr = exp.Parameters[0];
 | 
					            var newParameters = exp.Parameters.Select((a, b) => Expression.Parameter(a.Type, $"new{b}")).ToArray();
 | 
				
			||||||
            var body = Expression.Not(exp.Body);
 | 
					            var body = Expression.Not(exp.Body);
 | 
				
			||||||
            return Expression.Lambda<Func<T, bool>>(body, candidateExpr);
 | 
					            return Expression.Lambda(exp.Type, body, newParameters);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #region T1
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, bool>> And<T1>(this Expression<Func<T1, bool>> exp1, Expression<Func<T1, bool>> exp2) => And(exp1, true, exp2);
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp1"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <param name="exp2"></param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, bool>> And<T1>(this Expression<Func<T1, bool>> exp1, bool condition, Expression<Func<T1, bool>> exp2) => (Expression<Func<T1, bool>>)InternalAndOrExpression(condition, exp1, exp2, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, bool>> Or<T1>(this Expression<Func<T1, bool>> exp1, Expression<Func<T1, bool>> exp2) => Or(exp1, true, exp2);
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp1"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <param name="exp2"></param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, bool>> Or<T1>(this Expression<Func<T1, bool>> exp1, bool condition, Expression<Func<T1, bool>> exp2) => (Expression<Func<T1, bool>>)InternalAndOrExpression(condition, exp1, exp2, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 将 lambda 表达式取反
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, bool>> Not<T1>(this Expression<Func<T1, bool>> exp, bool condition = true) => (Expression<Func<T1, bool>>)InternalNotExpression(condition, exp);
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #region T1, T2
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, bool>> And<T1, T2>(this Expression<Func<T1, T2, bool>> exp1, Expression<Func<T1, T2, bool>> exp2) => And(exp1, true, exp2);
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp1"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <param name="exp2"></param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, bool>> And<T1, T2>(this Expression<Func<T1, T2, bool>> exp1, bool condition, Expression<Func<T1, T2, bool>> exp2) => (Expression<Func<T1, T2, bool>>)InternalAndOrExpression(condition, exp1, exp2, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, bool>> Or<T1, T2>(this Expression<Func<T1, T2, bool>> exp1, Expression<Func<T1, T2, bool>> exp2) => Or(exp1, true, exp2);
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp1"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <param name="exp2"></param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, bool>> Or<T1, T2>(this Expression<Func<T1, T2, bool>> exp1, bool condition, Expression<Func<T1, T2, bool>> exp2) => (Expression<Func<T1, T2, bool>>)InternalAndOrExpression(condition, exp1, exp2, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 将 lambda 表达式取反
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, bool>> Not<T1, T2>(this Expression<Func<T1, T2, bool>> exp, bool condition = true) => (Expression<Func<T1, T2, bool>>)InternalNotExpression(condition, exp);
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #region T1, T2, T3
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, bool>> And<T1, T2, T3>(this Expression<Func<T1, T2, T3, bool>> exp1, Expression<Func<T1, T2, T3, bool>> exp2) => And(exp1, true, exp2);
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp1"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <param name="exp2"></param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, bool>> And<T1, T2, T3>(this Expression<Func<T1, T2, T3, bool>> exp1, bool condition, Expression<Func<T1, T2, T3, bool>> exp2) => (Expression<Func<T1, T2, T3, bool>>)InternalAndOrExpression(condition, exp1, exp2, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, bool>> Or<T1, T2, T3>(this Expression<Func<T1, T2, T3, bool>> exp1, Expression<Func<T1, T2, T3, bool>> exp2) => Or(exp1, true, exp2);
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp1"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <param name="exp2"></param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, bool>> Or<T1, T2, T3>(this Expression<Func<T1, T2, T3, bool>> exp1, bool condition, Expression<Func<T1, T2, T3, bool>> exp2) => (Expression<Func<T1, T2, T3, bool>>)InternalAndOrExpression(condition, exp1, exp2, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 将 lambda 表达式取反
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, bool>> Not<T1, T2, T3>(this Expression<Func<T1, T2, T3, bool>> exp, bool condition = true) => (Expression<Func<T1, T2, T3, bool>>)InternalNotExpression(condition, exp);
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #region T1, T2, T3, T4
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, T4, bool>> And<T1, T2, T3, T4>(this Expression<Func<T1, T2, T3, T4, bool>> exp1, Expression<Func<T1, T2, T3, T4, bool>> exp2) => And(exp1, true, exp2);
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp1"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <param name="exp2"></param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, T4, bool>> And<T1, T2, T3, T4>(this Expression<Func<T1, T2, T3, T4, bool>> exp1, bool condition, Expression<Func<T1, T2, T3, T4, bool>> exp2) => (Expression<Func<T1, T2, T3, T4, bool>>)InternalAndOrExpression(condition, exp1, exp2, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, T4, bool>> Or<T1, T2, T3, T4>(this Expression<Func<T1, T2, T3, T4, bool>> exp1, Expression<Func<T1, T2, T3, T4, bool>> exp2) => Or(exp1, true, exp2);
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp1"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <param name="exp2"></param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, T4, bool>> Or<T1, T2, T3, T4>(this Expression<Func<T1, T2, T3, T4, bool>> exp1, bool condition, Expression<Func<T1, T2, T3, T4, bool>> exp2) => (Expression<Func<T1, T2, T3, T4, bool>>)InternalAndOrExpression(condition, exp1, exp2, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 将 lambda 表达式取反
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, T4, bool>> Not<T1, T2, T3, T4>(this Expression<Func<T1, T2, T3, T4, bool>> exp, bool condition = true) => (Expression<Func<T1, T2, T3, T4, bool>>)InternalNotExpression(condition, exp);
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #region T1, T2, T3, T4, T5
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, T4, T5, bool>> And<T1, T2, T3, T4, T5>(this Expression<Func<T1, T2, T3, T4, T5, bool>> exp1, Expression<Func<T1, T2, T3, T4, T5, bool>> exp2) => And(exp1, true, exp2);
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp1"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <param name="exp2"></param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, T4, T5, bool>> And<T1, T2, T3, T4, T5>(this Expression<Func<T1, T2, T3, T4, T5, bool>> exp1, bool condition, Expression<Func<T1, T2, T3, T4, T5, bool>> exp2) => (Expression<Func<T1, T2, T3, T4, T5, bool>>)InternalAndOrExpression(condition, exp1, exp2, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, T4, T5, bool>> Or<T1, T2, T3, T4, T5>(this Expression<Func<T1, T2, T3, T4, T5, bool>> exp1, Expression<Func<T1, T2, T3, T4, T5, bool>> exp2) => Or(exp1, true, exp2);
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp1"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <param name="exp2"></param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, T4, T5, bool>> Or<T1, T2, T3, T4, T5>(this Expression<Func<T1, T2, T3, T4, T5, bool>> exp1, bool condition, Expression<Func<T1, T2, T3, T4, T5, bool>> exp2) => (Expression<Func<T1, T2, T3, T4, T5, bool>>)InternalAndOrExpression(condition, exp1, exp2, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 将 lambda 表达式取反
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="exp"></param>
 | 
				
			||||||
 | 
					        /// <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
 | 
					        public static Expression<Func<T1, T2, T3, T4, T5, bool>> Not<T1, T2, T3, T4, T5>(this Expression<Func<T1, T2, T3, T4, T5, bool>> exp, bool condition = true) => (Expression<Func<T1, T2, T3, T4, T5, bool>>)InternalNotExpression(condition, exp);
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        internal static bool IsParameter(this Expression exp)
 | 
					        internal static bool IsParameter(this Expression exp)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var test = new TestParameterExpressionVisitor();
 | 
					            var test = new TestParameterExpressionVisitor();
 | 
				
			||||||
@@ -97,17 +237,23 @@ namespace System.Linq.Expressions
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    internal class NewExpressionVisitor : ExpressionVisitor
 | 
					    internal class NewExpressionVisitor : ExpressionVisitor
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        ParameterExpression _newParameter;
 | 
					        ParameterExpression[] _newParameters;
 | 
				
			||||||
        ParameterExpression _oldParameter;
 | 
					        ParameterExpression[] _oldParameters;
 | 
				
			||||||
        public NewExpressionVisitor(ParameterExpression newParam, ParameterExpression oldParam)
 | 
					        public NewExpressionVisitor(ParameterExpression newParam, ParameterExpression oldParam) : this(new[] { newParam }, new[] { oldParam }) { }
 | 
				
			||||||
 | 
					        public NewExpressionVisitor(ParameterExpression[] newParams, ParameterExpression[] oldParams)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this._newParameter = newParam;
 | 
					            this._newParameters = newParams;
 | 
				
			||||||
            this._oldParameter = oldParam;
 | 
					            this._oldParameters = oldParams;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        public Expression Replace(Expression exp) => this.Visit(exp);
 | 
					        public Expression Replace(Expression exp) => this.Visit(exp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        protected override Expression VisitParameter(ParameterExpression node) =>
 | 
					        protected override Expression VisitParameter(ParameterExpression node)
 | 
				
			||||||
            node == _oldParameter ? this._newParameter : node;
 | 
					        {
 | 
				
			||||||
 | 
					            for (var a = 0; a < _oldParameters.Length; a++)
 | 
				
			||||||
 | 
					                if (_oldParameters[a] == node)
 | 
				
			||||||
 | 
					                    return _newParameters[a];
 | 
				
			||||||
 | 
					            return node;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    internal class TestParameterExpressionVisitor : ExpressionVisitor
 | 
					    internal class TestParameterExpressionVisitor : ExpressionVisitor
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3319,7 +3319,6 @@
 | 
				
			|||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            使用 and 拼接两个 lambda 表达式
 | 
					            使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
            <typeparam name="T"></typeparam>
 | 
					 | 
				
			||||||
            <param name="exp1"></param>
 | 
					            <param name="exp1"></param>
 | 
				
			||||||
            <param name="condition">true 时生效</param>
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
            <param name="exp2"></param>
 | 
					            <param name="exp2"></param>
 | 
				
			||||||
@@ -3335,7 +3334,6 @@
 | 
				
			|||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            使用 or 拼接两个 lambda 表达式
 | 
					            使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
            <typeparam name="T"></typeparam>
 | 
					 | 
				
			||||||
            <param name="exp1"></param>
 | 
					            <param name="exp1"></param>
 | 
				
			||||||
            <param name="condition">true 时生效</param>
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
            <param name="exp2"></param>
 | 
					            <param name="exp2"></param>
 | 
				
			||||||
@@ -3345,7 +3343,158 @@
 | 
				
			|||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            将 lambda 表达式取反
 | 
					            将 lambda 表达式取反
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
            <typeparam name="T"></typeparam>
 | 
					            <param name="exp"></param>
 | 
				
			||||||
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.And``2(System.Linq.Expressions.Expression{System.Func{``0,``1,System.Boolean}},System.Linq.Expressions.Expression{System.Func{``0,``1,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.And``2(System.Linq.Expressions.Expression{System.Func{``0,``1,System.Boolean}},System.Boolean,System.Linq.Expressions.Expression{System.Func{``0,``1,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <param name="exp1"></param>
 | 
				
			||||||
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					            <param name="exp2"></param>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Or``2(System.Linq.Expressions.Expression{System.Func{``0,``1,System.Boolean}},System.Linq.Expressions.Expression{System.Func{``0,``1,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Or``2(System.Linq.Expressions.Expression{System.Func{``0,``1,System.Boolean}},System.Boolean,System.Linq.Expressions.Expression{System.Func{``0,``1,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <param name="exp1"></param>
 | 
				
			||||||
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					            <param name="exp2"></param>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Not``2(System.Linq.Expressions.Expression{System.Func{``0,``1,System.Boolean}},System.Boolean)">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            将 lambda 表达式取反
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <param name="exp"></param>
 | 
				
			||||||
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.And``3(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,System.Boolean}},System.Linq.Expressions.Expression{System.Func{``0,``1,``2,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.And``3(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,System.Boolean}},System.Boolean,System.Linq.Expressions.Expression{System.Func{``0,``1,``2,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <param name="exp1"></param>
 | 
				
			||||||
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					            <param name="exp2"></param>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Or``3(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,System.Boolean}},System.Linq.Expressions.Expression{System.Func{``0,``1,``2,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Or``3(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,System.Boolean}},System.Boolean,System.Linq.Expressions.Expression{System.Func{``0,``1,``2,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <param name="exp1"></param>
 | 
				
			||||||
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					            <param name="exp2"></param>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Not``3(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,System.Boolean}},System.Boolean)">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            将 lambda 表达式取反
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <param name="exp"></param>
 | 
				
			||||||
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.And``4(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,System.Boolean}},System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.And``4(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,System.Boolean}},System.Boolean,System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <param name="exp1"></param>
 | 
				
			||||||
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					            <param name="exp2"></param>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Or``4(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,System.Boolean}},System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Or``4(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,System.Boolean}},System.Boolean,System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <param name="exp1"></param>
 | 
				
			||||||
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					            <param name="exp2"></param>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Not``4(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,System.Boolean}},System.Boolean)">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            将 lambda 表达式取反
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <param name="exp"></param>
 | 
				
			||||||
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.And``5(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}},System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.And``5(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}},System.Boolean,System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 and 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <param name="exp1"></param>
 | 
				
			||||||
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					            <param name="exp2"></param>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Or``5(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}},System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Or``5(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}},System.Boolean,System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            使用 or 拼接两个 lambda 表达式
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <param name="exp1"></param>
 | 
				
			||||||
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
 | 
					            <param name="exp2"></param>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Not``5(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}},System.Boolean)">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            将 lambda 表达式取反
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
            <param name="exp"></param>
 | 
					            <param name="exp"></param>
 | 
				
			||||||
            <param name="condition">true 时生效</param>
 | 
					            <param name="condition">true 时生效</param>
 | 
				
			||||||
            <returns></returns>
 | 
					            <returns></returns>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user