I don't think you can.
I think the query will be converted to sql and sent to the database to enable filtering be done prior to loading the users from the database.
Your extension method won't be available in the database, all you can do is retrieve all users from the database and afterwards filter them according to your extension method.
I hope i don't have to point out the inherited performance issues with such a solution.
Yes, filtering after retrieving Users, currupts the pagination and total number. Unfortunately that's not a good solution in my case. :(
What do you recommend for such a scenario?
I can't say for certain without knowing what it is you do in your extension method, but most likely you would have to store it's result on the IUser with SetAttributeValue before hand. It would require you to keep it updated as well whenever something the method relies on changes.
That would enable you to run your query and filter in the database before loading the users.
I have defined an extension method on IUser to check whther the user is valid according to some criteria.
Then I have a UserQuery and I need to filter the result based on this extension method. I tried something like this;
This gives an System.ArgumentException that 'There is no attribute with the name IsValidMember for the type EPiServer.Common.Security.IUser'.
How can I possibly filter the users based on an extension method?