I want to create expression.Equal() with ignore case. Sample code:
if (!string.IsNullOrEmpty(request.BrandCode))
{
MemberExpression me = Expression.Property(parmExpression, "BrandCode");
ConstantExpression constant = Expression.Constant(request.BrandCode, typeof(string));
expbrandCode = Expression.Equal(me, constant);
}
if (!string.IsNullOrEmpty(request.CountryCode))
{
MemberExpression me = Expression.Property(parmExpression, "CountryCode");
ConstantExpression constant = Expression.Constant(request.CountryCode, typeof(string));
expCountryCode = Expression.Equal(me, constant);
}
var finalexpression = Expression.AndAlso(expbrandCode, expCountryCode);
Pass the final expression into a method which accepts the expression.
I tried to create a Methodinfo for Tolower, passed it in Expression.Equal() and that didn't work.
Any guidence would be helpful.
You could use string.Equals(string, string, StringComparison)
, like:
var expbrandCode = Expression.Call(typeof(string), "Equals", null, me, constant, Expression.Constant(StringComparison.CurrentCultureIgnoreCase));
Note that if you want to use the expression with Entity Framework or similar orms then it becomes complex... Not sure if they support translating that string.Equals()
overload.