SaaS CMS has officially launched! Learn more now.

Passing a filter expression to a method

Vote:
 

I'm using EPiServer Find to fetch all child pages, and I'm trying to make re-usable method which at it's heart is a Linq statement calling Find. Part of the linq is a "filter" method, which I'd like to be able to pass in. Currently, my method compiles but I cant correctly formulate something to pass into it.

The parameter giving me problems:

Expression> filterExpression

so i have a method that accepts the above filterExpression, but I've found no way of creating a value for that using types not already supported by the Episerverr Filters, in this instance I'd like to filter by type, but cant find a way to create a new filter to support new types of data. I've tried to use 'DelegateFilterBuilder' but again, new types dont seam to work

The heart of my resuable method I'm trying to create looks like this:

allChildPages = SearchClient.Instance.Search().FilterForVisitor()
.Filter(x => ((PageData)x).Ancestors().Match(pageRef.PageLink.ToString())) // find child pages of 'pageRef'
.Filter(filterExpression) // other potential filter
.OrderByDescending(orderExpression)

Part of my problem is EPiServer.Find.Api.Querying.Filter is an abstract class with nothing but static methods (according to resharper decompile), 

What am i missing? Is there some easy c# syntactic sugar I can use to solve my problem?

Using EPiServer CMS 11
Using EPiServer Find 13

#197567
Edited, Oct 08, 2018 10:52
Vote:
 

to answer my own question, I've fixed this issue with: 

.FilterByExactTypes(new List<Type>() { typeof(myPageType) })

I also figured out that you need to convert everything to types that "DelegateFilterBuilder" understands, but my attempt didn't work so I changed it too the above:   

Expression<Func<BaseRenderedPage, Filter>> filterExpression = x => x.GetType().ToString().Match(typeof(myPageType).ToString());  // this didn't work
#197572
Edited, Oct 08, 2018 12:45
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.