Merge pull request #8 from boris612/master
Enabled LessThan[OrEqual], GreaterThan[OrEqual] on strings
This commit is contained in:
		
						commit
						a1b3a3bda5
					
				| @ -123,5 +123,57 @@ namespace PoweredSoft.DynamicLinq.Test | ||||
|             b = Persons.AsQueryable().Where(t => t.FirstName.EndsWith("VID", StringComparison.OrdinalIgnoreCase)); | ||||
|             QueryableAssert.AreEqual(a, b, "CaseInsensitive"); | ||||
|         } | ||||
| 
 | ||||
|         [DataTestMethod] | ||||
|         [DataRow("Denis")] | ||||
|         [DataRow("Ann")] | ||||
|         [DataRow("Tony")] | ||||
|         public void LessThan(string firstName) | ||||
|         { | ||||
|             IQueryable<MockPersonObject> a, b; | ||||
|             | ||||
|             a = Persons.AsQueryable().Query(t => t.LessThan("FirstName", firstName)); | ||||
|             b = Persons.AsQueryable().Where(t => t.FirstName.CompareTo(firstName) < 0); | ||||
|             QueryableAssert.AreEqual(a, b); | ||||
|         } | ||||
| 
 | ||||
|         [DataTestMethod] | ||||
|         [DataRow("Denis")] | ||||
|         [DataRow("Ann")] | ||||
|         [DataRow("Tony")] | ||||
|         public void LessThanOrEqual(string firstName) | ||||
|         { | ||||
|             IQueryable<MockPersonObject> a, b; | ||||
| 
 | ||||
|             a = Persons.AsQueryable().Query(t => t.LessThanOrEqual("FirstName", firstName)); | ||||
|             b = Persons.AsQueryable().Where(t => t.FirstName.CompareTo(firstName) <= 0); | ||||
|             QueryableAssert.AreEqual(a, b); | ||||
|         } | ||||
| 
 | ||||
|         [DataTestMethod] | ||||
|         [DataRow("Denis")] | ||||
|         [DataRow("Ann")] | ||||
|         [DataRow("Tony")] | ||||
|         public void GreaterThan(string firstName) | ||||
|         { | ||||
|             IQueryable<MockPersonObject> a, b; | ||||
| 
 | ||||
|             a = Persons.AsQueryable().Query(t => t.GreaterThan("FirstName", firstName)); | ||||
|             b = Persons.AsQueryable().Where(t => t.FirstName.CompareTo(firstName) > 0); | ||||
|             QueryableAssert.AreEqual(a, b); | ||||
|         } | ||||
| 
 | ||||
|         [DataTestMethod] | ||||
|         [DataRow("Denis")] | ||||
|         [DataRow("Ann")] | ||||
|         [DataRow("Tony")] | ||||
|         public void GreaterThanOrEqual(string firstName) | ||||
|         { | ||||
|             IQueryable<MockPersonObject> a, b; | ||||
| 
 | ||||
|             a = Persons.AsQueryable().Query(t => t.GreaterThanOrEqual("FirstName", firstName)); | ||||
|             b = Persons.AsQueryable().Where(t => t.FirstName.CompareTo(firstName) >= 0); | ||||
|             QueryableAssert.AreEqual(a, b); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -78,5 +78,6 @@ namespace PoweredSoft.DynamicLinq | ||||
|         internal static readonly MethodInfo IndexOfMethod = typeof(string).GetMethod("IndexOf", new Type[] { typeof(string), typeof(StringComparison) }); | ||||
|         internal static readonly MethodInfo AnyMethod = typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).First(t => t.Name == "Any" && t.GetParameters().Count() == 2); | ||||
|         internal static readonly MethodInfo AllMethod = typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).First(t => t.Name == "All" && t.GetParameters().Count() == 2); | ||||
|         internal static readonly MethodInfo CompareToMethod = typeof(string).GetMethod("CompareTo", new Type[] { typeof(string) }); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -47,13 +47,33 @@ namespace PoweredSoft.DynamicLinq.Helpers | ||||
|                     ret = Expression.NotEqual(member, constant); | ||||
|             } | ||||
|             else if (conditionOperator == ConditionOperators.GreaterThan) | ||||
|             { | ||||
|                 if (member.Type == stringType) | ||||
|                     ret = Expression.GreaterThan(Expression.Call(member, Constants.CompareToMethod, constant), Expression.Constant(0)); | ||||
|                 else | ||||
|                     ret = Expression.GreaterThan(member, constant); | ||||
|             } | ||||
|             else if (conditionOperator == ConditionOperators.GreaterThanOrEqual) | ||||
|             { | ||||
|                 if (member.Type == stringType) | ||||
|                     ret = Expression.GreaterThanOrEqual(Expression.Call(member, Constants.CompareToMethod, constant), Expression.Constant(0)); | ||||
|                 else | ||||
|                     ret = Expression.GreaterThanOrEqual(member, constant); | ||||
|             } | ||||
|             else if (conditionOperator == ConditionOperators.LessThan) | ||||
|             { | ||||
|                 if (member.Type == stringType) | ||||
|                     ret = Expression.LessThan(Expression.Call(member, Constants.CompareToMethod, constant), Expression.Constant(0)); | ||||
|                 else | ||||
|                     ret = Expression.LessThan(member, constant); | ||||
|             } | ||||
|             else if (conditionOperator == ConditionOperators.LessThanOrEqual) | ||||
|             { | ||||
|                 if (member.Type == stringType) | ||||
|                     ret = Expression.LessThanOrEqual(Expression.Call(member, Constants.CompareToMethod, constant), Expression.Constant(0)); | ||||
|                 else | ||||
|                     ret = Expression.LessThanOrEqual(member, constant); | ||||
|             }            | ||||
|             else if (conditionOperator == ConditionOperators.Contains) | ||||
|             { | ||||
|                 if (member.Type == stringType && stringComparision.HasValue) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user