StringComparison Support.
This commit is contained in:
parent
a8981e9ad7
commit
cbd60bad8c
@ -37,5 +37,17 @@ namespace PoweredSoft.DynamicLinq.Test.Helpers
|
|||||||
{
|
{
|
||||||
Assert.IsFalse(_sameList(a, b));
|
Assert.IsFalse(_sameList(a, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void AreEqual<T>(IQueryable<T> a, IQueryable<T> b, string message)
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
Assert.IsTrue(_sameList(a, b), message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AreNotEqual<T>(IQueryable<T> a, IQueryable<T> b, string message)
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
Assert.IsFalse(_sameList(a, b), message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,7 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="HelpersTests.cs" />
|
<Compile Include="HelpersTests.cs" />
|
||||||
<Compile Include="EntityFrameworkTests.cs" />
|
<Compile Include="EntityFrameworkTests.cs" />
|
||||||
|
<Compile Include="StringComparision.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
102
PoweredSoft.DynamicLinq.Test/StringComparision.cs
Normal file
102
PoweredSoft.DynamicLinq.Test/StringComparision.cs
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using PoweredSoft.DynamicLinq.Extensions;
|
||||||
|
using PoweredSoft.DynamicLinq.Test.Helpers;
|
||||||
|
|
||||||
|
namespace PoweredSoft.DynamicLinq.Test
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class StringComparisionTests
|
||||||
|
{
|
||||||
|
internal List<MockPersonObject> Persons = new List<MockPersonObject>
|
||||||
|
{
|
||||||
|
new MockPersonObject { FirstName = "David", LastName = "Lebee", Age = 28 },
|
||||||
|
new MockPersonObject { FirstName = "Michaela", LastName = "Vickar", Age = 27 },
|
||||||
|
new MockPersonObject { FirstName = "John", LastName = "Doe", Age = 28 },
|
||||||
|
new MockPersonObject { FirstName = "Chuck", LastName = "Norris", Age = 50 },
|
||||||
|
new MockPersonObject { FirstName = "Michael", LastName = "Jackson", Age = 58 }
|
||||||
|
};
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Equal()
|
||||||
|
{
|
||||||
|
IQueryable<MockPersonObject> a, b;
|
||||||
|
|
||||||
|
// case sensitive.
|
||||||
|
a = Persons.AsQueryable().Query(t => t.Equal("FirstName", "David", stringComparision: null));
|
||||||
|
b = Persons.AsQueryable().Where(t => t.FirstName == "David");
|
||||||
|
QueryableAssert.AreEqual(a, b, "CaseSensitive");
|
||||||
|
|
||||||
|
// not case sensitive
|
||||||
|
a = Persons.AsQueryable().Query(t => t.Equal("FirstName", "DAVID", stringComparision: StringComparison.OrdinalIgnoreCase));
|
||||||
|
b = Persons.AsQueryable().Where(t => t.FirstName.Equals("DAVID", StringComparison.OrdinalIgnoreCase));
|
||||||
|
QueryableAssert.AreEqual(a, b, "CaseInsensitive");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void NotEqual()
|
||||||
|
{
|
||||||
|
IQueryable<MockPersonObject> a, b;
|
||||||
|
|
||||||
|
// case sensitive.
|
||||||
|
a = Persons.AsQueryable().Query(t => t.NotEqual("FirstName", "David", stringComparision: null));
|
||||||
|
b = Persons.AsQueryable().Where(t => t.FirstName != "David");
|
||||||
|
QueryableAssert.AreEqual(a, b, "CaseSensitive");
|
||||||
|
|
||||||
|
// not case sensitive
|
||||||
|
a = Persons.AsQueryable().Query(t => t.NotEqual("FirstName", "DAVID", stringComparision: StringComparison.OrdinalIgnoreCase));
|
||||||
|
b = Persons.AsQueryable().Where(t => !t.FirstName.Equals("DAVID", StringComparison.OrdinalIgnoreCase));
|
||||||
|
QueryableAssert.AreEqual(a, b, "CaseInsensitive");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Contains()
|
||||||
|
{
|
||||||
|
IQueryable<MockPersonObject> a, b;
|
||||||
|
|
||||||
|
// case sensitive.
|
||||||
|
a = Persons.AsQueryable().Query(t => t.Contains("FirstName", "vi", stringComparision: null));
|
||||||
|
b = Persons.AsQueryable().Where(t => t.FirstName.Contains("vi"));
|
||||||
|
QueryableAssert.AreEqual(a, b, "CaseSensitive");
|
||||||
|
|
||||||
|
// not case sensitive
|
||||||
|
a = Persons.AsQueryable().Query(t => t.Contains("FirstName", "VI", stringComparision: StringComparison.OrdinalIgnoreCase));
|
||||||
|
b = Persons.AsQueryable().Where(t => t.FirstName.IndexOf("VI", StringComparison.OrdinalIgnoreCase) > -1);
|
||||||
|
QueryableAssert.AreEqual(a, b, "CaseInsensitive");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void StartsWith()
|
||||||
|
{
|
||||||
|
IQueryable<MockPersonObject> a, b;
|
||||||
|
|
||||||
|
// case sensitive.
|
||||||
|
a = Persons.AsQueryable().Query(t => t.StartsWith("FirstName", "Da", stringComparision: null));
|
||||||
|
b = Persons.AsQueryable().Where(t => t.FirstName.StartsWith("Da"));
|
||||||
|
QueryableAssert.AreEqual(a, b, "CaseSensitive");
|
||||||
|
|
||||||
|
// not case sensitive
|
||||||
|
a = Persons.AsQueryable().Query(t => t.StartsWith("FirstName", "DA", stringComparision: StringComparison.OrdinalIgnoreCase));
|
||||||
|
b = Persons.AsQueryable().Where(t => t.FirstName.StartsWith("DA", StringComparison.OrdinalIgnoreCase));
|
||||||
|
QueryableAssert.AreEqual(a, b, "CaseInsensitive");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void EndsWith()
|
||||||
|
{
|
||||||
|
IQueryable<MockPersonObject> a, b;
|
||||||
|
|
||||||
|
// case sensitive.
|
||||||
|
a = Persons.AsQueryable().Query(t => t.EndsWith("FirstName", "vid", stringComparision: null));
|
||||||
|
b = Persons.AsQueryable().Where(t => t.FirstName.EndsWith("vid"));
|
||||||
|
QueryableAssert.AreEqual(a, b, "CaseSensitive");
|
||||||
|
|
||||||
|
// not case sensitive
|
||||||
|
a = Persons.AsQueryable().Query(t => t.EndsWith("FirstName", "VID", stringComparision: StringComparison.OrdinalIgnoreCase));
|
||||||
|
b = Persons.AsQueryable().Where(t => t.FirstName.EndsWith("VID", StringComparison.OrdinalIgnoreCase));
|
||||||
|
QueryableAssert.AreEqual(a, b, "CaseInsensitive");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -41,9 +41,13 @@ namespace PoweredSoft.DynamicLinq
|
|||||||
|
|
||||||
internal static class Constants
|
internal static class Constants
|
||||||
{
|
{
|
||||||
|
internal static readonly MethodInfo StringEqualWithComparisation = typeof(string).GetMethod("Equals", new Type[] { typeof(string), typeof(StringComparison) });
|
||||||
internal static readonly MethodInfo ContainsMethod = typeof(string).GetMethod("Contains");
|
internal static readonly MethodInfo ContainsMethod = typeof(string).GetMethod("Contains");
|
||||||
internal static readonly MethodInfo StartsWithMethod = typeof(string).GetMethod("StartsWith", new Type[] { typeof(string) });
|
internal static readonly MethodInfo StartsWithMethod = typeof(string).GetMethod("StartsWith", new Type[] { typeof(string) });
|
||||||
|
internal static readonly MethodInfo StartsWithMethodWithComparisation = typeof(string).GetMethod("StartsWith", new Type[] { typeof(string), typeof(StringComparison) });
|
||||||
internal static readonly MethodInfo EndsWithMethod = typeof(string).GetMethod("EndsWith", new Type[] { typeof(string) });
|
internal static readonly MethodInfo EndsWithMethod = typeof(string).GetMethod("EndsWith", new Type[] { typeof(string) });
|
||||||
|
internal static readonly MethodInfo EndsWithMethodWithComparisation = typeof(string).GetMethod("EndsWith", new Type[] { typeof(string), typeof(StringComparison) });
|
||||||
|
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 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 AllMethod = typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).First(t => t.Name == "All" && t.GetParameters().Count() == 2);
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,8 @@ namespace PoweredSoft.DynamicLinq.Fluent
|
|||||||
filter.ConvertStrategy,
|
filter.ConvertStrategy,
|
||||||
filter.CollectionHandling,
|
filter.CollectionHandling,
|
||||||
parameter: parameter,
|
parameter: parameter,
|
||||||
nullChecking: IsNullCheckingEnabled
|
nullChecking: IsNullCheckingEnabled,
|
||||||
|
stringComparision: filter.StringComparisation
|
||||||
);
|
);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -23,7 +23,7 @@ namespace PoweredSoft.DynamicLinq.Fluent
|
|||||||
|
|
||||||
public virtual QueryBuilderBase Compare(string path, ConditionOperators conditionOperators, object value,
|
public virtual QueryBuilderBase Compare(string path, ConditionOperators conditionOperators, object value,
|
||||||
QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField,
|
QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField,
|
||||||
bool and = true, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
bool and = true, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
{
|
{
|
||||||
Filters.Add(new QueryBuilderFilter
|
Filters.Add(new QueryBuilderFilter
|
||||||
{
|
{
|
||||||
@ -32,7 +32,8 @@ namespace PoweredSoft.DynamicLinq.Fluent
|
|||||||
Path = path,
|
Path = path,
|
||||||
Value = value,
|
Value = value,
|
||||||
ConvertStrategy = convertStrategy,
|
ConvertStrategy = convertStrategy,
|
||||||
CollectionHandling = collectionHandling
|
CollectionHandling = collectionHandling,
|
||||||
|
StringComparisation = stringComparision
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -7,12 +7,12 @@ namespace PoweredSoft.DynamicLinq.Fluent
|
|||||||
public abstract partial class QueryBuilderBase
|
public abstract partial class QueryBuilderBase
|
||||||
{
|
{
|
||||||
public QueryBuilderBase And(string path, ConditionOperators conditionOperator, object value,
|
public QueryBuilderBase And(string path, ConditionOperators conditionOperator, object value,
|
||||||
QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> Compare(path, conditionOperator, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, and: true);
|
=> Compare(path, conditionOperator, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, and: true, stringComparision: stringComparision);
|
||||||
|
|
||||||
public QueryBuilderBase Or(string path, ConditionOperators conditionOperator, object value,
|
public QueryBuilderBase Or(string path, ConditionOperators conditionOperator, object value,
|
||||||
QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> Compare(path, conditionOperator, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, and: false);
|
=> Compare(path, conditionOperator, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, and: false, stringComparision: stringComparision);
|
||||||
|
|
||||||
public QueryBuilderBase And(Action<QueryBuilderBase> subQuery)
|
public QueryBuilderBase And(Action<QueryBuilderBase> subQuery)
|
||||||
=> SubQuery(subQuery, true);
|
=> SubQuery(subQuery, true);
|
||||||
@ -21,25 +21,25 @@ namespace PoweredSoft.DynamicLinq.Fluent
|
|||||||
=> SubQuery(subQuery, false);
|
=> SubQuery(subQuery, false);
|
||||||
|
|
||||||
#region equal
|
#region equal
|
||||||
public QueryBuilderBase Equal(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase Equal(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> And(path, ConditionOperators.Equal, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> And(path, ConditionOperators.Equal, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
|
|
||||||
public QueryBuilderBase AndEqual(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase AndEqual(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> And(path, ConditionOperators.Equal, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> And(path, ConditionOperators.Equal, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
|
|
||||||
public QueryBuilderBase OrEqual(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase OrEqual(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> Or(path, ConditionOperators.Equal, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> Or(path, ConditionOperators.Equal, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region not equal
|
#region not equal
|
||||||
public QueryBuilderBase NotEqual(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase NotEqual(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> And(path, ConditionOperators.NotEqual, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> And(path, ConditionOperators.NotEqual, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
|
|
||||||
public QueryBuilderBase AndNotEqual(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase AndNotEqual(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> And(path, ConditionOperators.NotEqual, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> And(path, ConditionOperators.NotEqual, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
|
|
||||||
public QueryBuilderBase OrNotEqual(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase OrNotEqual(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> Or(path, ConditionOperators.NotEqual, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> Or(path, ConditionOperators.NotEqual, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GreaterThan
|
#region GreaterThan
|
||||||
@ -87,36 +87,36 @@ namespace PoweredSoft.DynamicLinq.Fluent
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region contains
|
#region contains
|
||||||
public QueryBuilderBase Contains(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase Contains(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> And(path, ConditionOperators.Contains, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> And(path, ConditionOperators.Contains, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
|
|
||||||
public QueryBuilderBase AndContains(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase AndContains(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> And(path, ConditionOperators.Contains, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> And(path, ConditionOperators.Contains, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
|
|
||||||
public QueryBuilderBase OrContains(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase OrContains(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> Or(path, ConditionOperators.Contains, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> Or(path, ConditionOperators.Contains, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region starts with
|
#region starts with
|
||||||
public QueryBuilderBase StartsWith(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase StartsWith(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> And(path, ConditionOperators.StartsWith, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> And(path, ConditionOperators.StartsWith, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
|
|
||||||
public QueryBuilderBase AndStartsWith(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase AndStartsWith(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> And(path, ConditionOperators.StartsWith, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> And(path, ConditionOperators.StartsWith, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
|
|
||||||
public QueryBuilderBase OrStartsWith(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase OrStartsWith(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> Or(path, ConditionOperators.StartsWith, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> Or(path, ConditionOperators.StartsWith, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ends with
|
#region ends with
|
||||||
public QueryBuilderBase EndsWith(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase EndsWith(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> And(path, ConditionOperators.EndsWith, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> And(path, ConditionOperators.EndsWith, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
|
|
||||||
public QueryBuilderBase AndEndsWith(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase AndEndsWith(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> And(path, ConditionOperators.EndsWith, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> And(path, ConditionOperators.EndsWith, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
|
|
||||||
public QueryBuilderBase OrEndsWith(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any)
|
public QueryBuilderBase OrEndsWith(string path, object value, QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
||||||
=> Or(path, ConditionOperators.EndsWith, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling);
|
=> Or(path, ConditionOperators.EndsWith, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,5 +15,6 @@ namespace PoweredSoft.DynamicLinq.Fluent
|
|||||||
public QueryConvertStrategy ConvertStrategy { get; set; }
|
public QueryConvertStrategy ConvertStrategy { get; set; }
|
||||||
public List<QueryBuilderFilter> Filters { get; set; } = new List<QueryBuilderFilter>();
|
public List<QueryBuilderFilter> Filters { get; set; } = new List<QueryBuilderFilter>();
|
||||||
public QueryCollectionHandling CollectionHandling { get; set; }
|
public QueryCollectionHandling CollectionHandling { get; set; }
|
||||||
|
public StringComparison? StringComparisation { get; set; } = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ namespace PoweredSoft.DynamicLinq.Helpers
|
|||||||
{
|
{
|
||||||
public static class QueryableHelpers
|
public static class QueryableHelpers
|
||||||
{
|
{
|
||||||
public static Expression GetConditionExpressionForMember(ParameterExpression parameter, Expression member, ConditionOperators conditionOperator, ConstantExpression constant)
|
public static Expression GetConditionExpressionForMember(ParameterExpression parameter, Expression member, ConditionOperators conditionOperator, ConstantExpression constant, StringComparison? stringComparision)
|
||||||
{
|
{
|
||||||
if (parameter == null)
|
if (parameter == null)
|
||||||
throw new ArgumentNullException("parameter");
|
throw new ArgumentNullException("parameter");
|
||||||
@ -21,12 +21,25 @@ namespace PoweredSoft.DynamicLinq.Helpers
|
|||||||
if (constant == null)
|
if (constant == null)
|
||||||
throw new ArgumentNullException("constant");
|
throw new ArgumentNullException("constant");
|
||||||
|
|
||||||
|
|
||||||
|
Type stringType = typeof(string);
|
||||||
|
|
||||||
Expression ret = null;
|
Expression ret = null;
|
||||||
|
|
||||||
if (conditionOperator == ConditionOperators.Equal)
|
if (conditionOperator == ConditionOperators.Equal)
|
||||||
ret = Expression.Equal(member, constant);
|
{
|
||||||
|
if (member.Type == stringType && stringComparision.HasValue)
|
||||||
|
ret = Expression.Call(member, Constants.StringEqualWithComparisation, constant, Expression.Constant(stringComparision.Value));
|
||||||
|
else
|
||||||
|
ret = Expression.Equal(member, constant);
|
||||||
|
}
|
||||||
else if (conditionOperator == ConditionOperators.NotEqual)
|
else if (conditionOperator == ConditionOperators.NotEqual)
|
||||||
ret = Expression.NotEqual(member, constant);
|
{
|
||||||
|
if (member.Type == stringType && stringComparision.HasValue)
|
||||||
|
ret = Expression.Not(Expression.Call(member, Constants.StringEqualWithComparisation, constant, Expression.Constant(stringComparision.Value)));
|
||||||
|
else
|
||||||
|
ret = Expression.NotEqual(member, constant);
|
||||||
|
}
|
||||||
else if (conditionOperator == ConditionOperators.GreaterThan)
|
else if (conditionOperator == ConditionOperators.GreaterThan)
|
||||||
ret = Expression.GreaterThan(member, constant);
|
ret = Expression.GreaterThan(member, constant);
|
||||||
else if (conditionOperator == ConditionOperators.GreaterThanOrEqual)
|
else if (conditionOperator == ConditionOperators.GreaterThanOrEqual)
|
||||||
@ -36,11 +49,26 @@ namespace PoweredSoft.DynamicLinq.Helpers
|
|||||||
else if (conditionOperator == ConditionOperators.LessThanOrEqual)
|
else if (conditionOperator == ConditionOperators.LessThanOrEqual)
|
||||||
ret = Expression.LessThanOrEqual(member, constant);
|
ret = Expression.LessThanOrEqual(member, constant);
|
||||||
else if (conditionOperator == ConditionOperators.Contains)
|
else if (conditionOperator == ConditionOperators.Contains)
|
||||||
ret = Expression.Call(member, Constants.ContainsMethod, constant);
|
{
|
||||||
|
if (member.Type == stringType && stringComparision.HasValue)
|
||||||
|
ret = Expression.GreaterThan(Expression.Call(member, Constants.IndexOfMethod, constant, Expression.Constant(stringComparision.Value)), Expression.Constant(-1));
|
||||||
|
else
|
||||||
|
ret = Expression.Call(member, Constants.ContainsMethod, constant);
|
||||||
|
}
|
||||||
else if (conditionOperator == ConditionOperators.StartsWith)
|
else if (conditionOperator == ConditionOperators.StartsWith)
|
||||||
ret = Expression.Call(member, Constants.StartsWithMethod, constant);
|
{
|
||||||
|
if (member.Type == stringType && stringComparision.HasValue)
|
||||||
|
ret = Expression.Call(member, Constants.StartsWithMethodWithComparisation, constant, Expression.Constant(stringComparision.Value));
|
||||||
|
else
|
||||||
|
ret = Expression.Call(member, Constants.StartsWithMethod, constant);
|
||||||
|
}
|
||||||
else if (conditionOperator == ConditionOperators.EndsWith)
|
else if (conditionOperator == ConditionOperators.EndsWith)
|
||||||
ret = Expression.Call(member, Constants.EndsWithMethod, constant);
|
{
|
||||||
|
if (member.Type == stringType && stringComparision.HasValue)
|
||||||
|
ret = Expression.Call(member, Constants.EndsWithMethodWithComparisation, constant, Expression.Constant(stringComparision.Value));
|
||||||
|
else
|
||||||
|
ret = Expression.Call(member, Constants.EndsWithMethod, constant);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
throw new ArgumentException("conditionOperator", "Must supply a known condition operator");
|
throw new ArgumentException("conditionOperator", "Must supply a known condition operator");
|
||||||
|
|
||||||
@ -124,7 +152,7 @@ namespace PoweredSoft.DynamicLinq.Helpers
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal static Expression InternalCreateFilterExpression(int recursionStep, Type type, ParameterExpression parameter, Expression current, List<string> parts,
|
internal static Expression InternalCreateFilterExpression(int recursionStep, Type type, ParameterExpression parameter, Expression current, List<string> parts,
|
||||||
ConditionOperators condition, object value, QueryConvertStrategy convertStrategy, QueryCollectionHandling collectionHandling, bool nullChecking)
|
ConditionOperators condition, object value, QueryConvertStrategy convertStrategy, QueryCollectionHandling collectionHandling, bool nullChecking, StringComparison? stringComparison)
|
||||||
{
|
{
|
||||||
var partStr = parts.First();
|
var partStr = parts.First();
|
||||||
var isLast = parts.Count == 1;
|
var isLast = parts.Count == 1;
|
||||||
@ -142,7 +170,7 @@ namespace PoweredSoft.DynamicLinq.Helpers
|
|||||||
if (isLast)
|
if (isLast)
|
||||||
{
|
{
|
||||||
var constant = QueryableHelpers.ResolveConstant(memberExpression, value, convertStrategy);
|
var constant = QueryableHelpers.ResolveConstant(memberExpression, value, convertStrategy);
|
||||||
var filterExpression = QueryableHelpers.GetConditionExpressionForMember(parameter, memberExpression, condition, constant);
|
var filterExpression = QueryableHelpers.GetConditionExpressionForMember(parameter, memberExpression, condition, constant, stringComparison);
|
||||||
var lambda = Expression.Lambda(filterExpression, parameter);
|
var lambda = Expression.Lambda(filterExpression, parameter);
|
||||||
return lambda;
|
return lambda;
|
||||||
}
|
}
|
||||||
@ -156,7 +184,7 @@ namespace PoweredSoft.DynamicLinq.Helpers
|
|||||||
{
|
{
|
||||||
var listGenericArgumentType = memberExpression.Type.GetGenericArguments().First();
|
var listGenericArgumentType = memberExpression.Type.GetGenericArguments().First();
|
||||||
var innerParameter = Expression.Parameter(listGenericArgumentType, $"t{++recursionStep}");
|
var innerParameter = Expression.Parameter(listGenericArgumentType, $"t{++recursionStep}");
|
||||||
var innerLambda = InternalCreateFilterExpression(recursionStep, listGenericArgumentType, innerParameter, innerParameter, parts.Skip(1).ToList(), condition, value, convertStrategy, collectionHandling, nullChecking);
|
var innerLambda = InternalCreateFilterExpression(recursionStep, listGenericArgumentType, innerParameter, innerParameter, parts.Skip(1).ToList(), condition, value, convertStrategy, collectionHandling, nullChecking, stringComparison);
|
||||||
|
|
||||||
// the collection method.
|
// the collection method.
|
||||||
var collectionMethod = GetCollectionMethod(collectionHandling);
|
var collectionMethod = GetCollectionMethod(collectionHandling);
|
||||||
@ -175,12 +203,12 @@ namespace PoweredSoft.DynamicLinq.Helpers
|
|||||||
{
|
{
|
||||||
if (nullCheckExpression != null)
|
if (nullCheckExpression != null)
|
||||||
{
|
{
|
||||||
var pathExpr = InternalCreateFilterExpression(recursionStep, type, parameter, memberExpression, parts.Skip(1).ToList(), condition, value, convertStrategy, collectionHandling, nullChecking);
|
var pathExpr = InternalCreateFilterExpression(recursionStep, type, parameter, memberExpression, parts.Skip(1).ToList(), condition, value, convertStrategy, collectionHandling, nullChecking, stringComparison);
|
||||||
var nullCheckResult = Expression.AndAlso(nullCheckExpression, pathExpr);
|
var nullCheckResult = Expression.AndAlso(nullCheckExpression, pathExpr);
|
||||||
return nullCheckResult;
|
return nullCheckResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
return InternalCreateFilterExpression(recursionStep, type, parameter, memberExpression, parts.Skip(1).ToList(), condition, value, convertStrategy, collectionHandling, nullChecking);
|
return InternalCreateFilterExpression(recursionStep, type, parameter, memberExpression, parts.Skip(1).ToList(), condition, value, convertStrategy, collectionHandling, nullChecking, stringComparison);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,13 +228,14 @@ namespace PoweredSoft.DynamicLinq.Helpers
|
|||||||
QueryConvertStrategy convertStrategy,
|
QueryConvertStrategy convertStrategy,
|
||||||
QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any,
|
QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any,
|
||||||
ParameterExpression parameter = null,
|
ParameterExpression parameter = null,
|
||||||
bool nullChecking = false)
|
bool nullChecking = false,
|
||||||
|
StringComparison? stringComparision = null)
|
||||||
{
|
{
|
||||||
if (parameter == null)
|
if (parameter == null)
|
||||||
parameter = Expression.Parameter(typeof(T), "t");
|
parameter = Expression.Parameter(typeof(T), "t");
|
||||||
|
|
||||||
var parts = path.Split('.').ToList();
|
var parts = path.Split('.').ToList();
|
||||||
var result = InternalCreateFilterExpression(1, typeof(T), parameter, parameter, parts, condition, value, convertStrategy, collectionHandling, nullChecking);
|
var result = InternalCreateFilterExpression(1, typeof(T), parameter, parameter, parts, condition, value, convertStrategy, collectionHandling, nullChecking, stringComparision);
|
||||||
var ret = result as Expression<Func<T, bool>>;
|
var ret = result as Expression<Func<T, bool>>;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user