Created
July 21, 2020 07:12
-
-
Save enisn/0d1c0742e712e46d8596b6beb9722c6c to your computer and use it in GitHub Desktop.
Array from dto search in db
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using AutoFilterer.Attributes; | |
using System.Linq; | |
using System.Linq.Expressions; | |
using System.Reflection; | |
namespace AutoFilterer.Types | |
{ | |
public class ArraySearchFilteringAttribute : FilteringOptionsBaseAttribute | |
{ | |
public override Expression BuildExpression(Expression expressionBody, PropertyInfo targetProperty, PropertyInfo filterProperty, object value) | |
{ | |
// db.Books.Where(x => value.Contains(x.TotalPage)) | |
var type = targetProperty.PropertyType; | |
var prop = Expression.Property(expressionBody, targetProperty.Name); | |
var containsMethod = typeof(Enumerable).GetMethods().FirstOrDefault(x => x.Name == nameof(Enumerable.Contains)).MakeGenericMethod(type); | |
var containsExpression = Expression.Call( | |
method: containsMethod, | |
arguments: new Expression[] | |
{ | |
Expression.Constant(value), | |
Expression.Property(expressionBody, targetProperty.Name) | |
}); | |
return containsExpression; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment