Suppose something like this :
public static IQueryable<T> Find<T>(IQueryable<T> query, string value, params Expression<Func<T, object>>[] subSelectors) where T : class
{
foreach (var include in subSelectors)
{
var entityType = include.Body.Type.GetGenericArguments().First();
var properties = from p in entityType.GetProperties()
where Attribute.IsDefined(p, typeof(FilterAttribute))
select p;
}
}
This method is called from another assembly, exemple call of this method :
var container = new List<MyClass>();
var q = (from m in container
select m).AsQueryable();
SimpleFilter.Find(q, "something", m => m.Navigation);
For the T parameter is ok I see my custom attribute. But form the lambda expression I cant see my custom attribute.
Assuming you just want to see if each selector specified has the attribute:
var member = ((MemberExpression) include.Body).Member;
bool hasAttribute = Attribute.IsDefined(member, typeof (FilterAttribute));
it isn't clear how you intend to plug that into the rest of the Find method, but I think that covers the main thrust of the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With