3

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.

1
  • btw... entityType is simpler as typeof(T) here, no? Commented Dec 15, 2011 at 21:33

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.