Consider the following codes :
public static IQueryable<T> WhereDynamic<T>(this IQueryable<T> sourceList, string query)
{
if (string.IsNullOrEmpty(query))
{
return sourceList;
}
try
{
var properties = typeof(T).GetProperties()
.Where(x => x.CanRead && x.CanWrite && !x.GetGetMethod().IsVirtual);
//Expression
sourceList = sourceList.Where(c =>
properties.Any(p => p.GetValue(c) != null && p.GetValue(c).ToString()
.Contains(query, StringComparison.InvariantCultureIgnoreCase)));
}
catch (Exception e)
{
Console.WriteLine(e);
}
return sourceList;
}
I have created a project of type .Net Standard 2.0 and I want to use the above code in it. But the problem is that it is not possible to use this overload:
.Contains method (query, StringComparison.InvariantCultureIgnoreCase)
It does not exist. While in a .NET Core project, there is no problem.
Do you have a solution or alternative to that overload of the Contains()
method?