/// <summary> /// memberAccessor==value /// </summary> /// <param name="memberAccessor"></param> /// <param name="value"></param> /// <returns></returns> protected virtual Expression GetEqualExpression(MemberExpression memberAccessor, object value) { Expression constant = ConstantExpression(ChangeValueTypeToMemberType(memberAccessor.Type, value)); MemberExpression nullableStructValueAccessor = memberAccessor.GetNullableStructValueAccessExpression(); if (nullableStructValueAccessor == null || (nullableStructValueAccessor != null && value == null)) { return(Expression.Equal(memberAccessor, constant)); } else { return(Expression.Equal(nullableStructValueAccessor, constant).AttachAndAlsoMemberNotNullCheckExpressionOnLeft(memberAccessor)); } }
protected virtual Expression GetGreaterThanOrEqualExpression(MemberExpression memberAccessor, object value) { if (value is null) { throw new ArgumentNullException(nameof(value)); } //member>=constant Expression constant = ConstantExpression(ChangeValueTypeToMemberType(memberAccessor.Type, value)); MemberExpression nullableStructValueAccessor = memberAccessor.GetNullableStructValueAccessExpression(); if (nullableStructValueAccessor == null) { return(Expression.GreaterThanOrEqual(memberAccessor, constant)); } else { return(Expression.GreaterThanOrEqual(nullableStructValueAccessor, constant).AttachAndAlsoMemberNotNullCheckExpressionOnLeft(memberAccessor)); } }
protected virtual Expression GetInExpression(MemberExpression memberAccessor, object value) { if (value is null) { throw new ArgumentNullException(nameof(value)); } Expression result = null; MemberExpression nullableStructValueAccessor = memberAccessor.GetNullableStructValueAccessExpression(); MemberExpression currentMemberAccessor = nullableStructValueAccessor == null ? memberAccessor : nullableStructValueAccessor; foreach (object item in (IEnumerable)value) { Expression constant = ConstantExpression(ChangeValueTypeToMemberType(memberAccessor.Type, item)); result = result == null ? Expression.Equal(currentMemberAccessor, constant) : Expression.OrElse(result, Expression.Equal(currentMemberAccessor, constant)); } if (nullableStructValueAccessor != null) { result = result.AttachAndAlsoMemberNotNullCheckExpressionOnLeft(memberAccessor); } return(result); }
protected virtual Expression GetBetweenExpression(MemberExpression memberAccessor, object value) { //member>=constant[0]&&member<=constant[1] if (value is object[] valueArray) { MemberExpression nullableStructValueAccessor = memberAccessor.GetNullableStructValueAccessExpression(); MemberExpression currentMemberAccessor = nullableStructValueAccessor != null ? nullableStructValueAccessor : memberAccessor; Expression constantStart = ConstantExpression(ChangeValueTypeToMemberType(currentMemberAccessor.Type, valueArray[0])); Expression constantEnd = ConstantExpression(ChangeValueTypeToMemberType(currentMemberAccessor.Type, valueArray[1])); Expression result = Expression.AndAlso( Expression.GreaterThanOrEqual(currentMemberAccessor, constantStart), Expression.LessThanOrEqual(currentMemberAccessor, constantEnd) ); if (nullableStructValueAccessor != null) { result = result.AttachAndAlsoMemberNotNullCheckExpressionOnLeft(memberAccessor); } return(result); } else { throw new ArgumentException(nameof(value) + " must be array which length==2", nameof(value)); } }