/// <summary> /// Create a filter parameter /// </summary> /// <param name="documentSearch">Document search engine</param> /// <param name="conditional">Conditional to add parameter</param> /// <param name="fieldExpression">Expression used to find field name</param> /// <param name="query">Query used to make filter</param> /// <param name="instance">Instance of parameter ready to configure</param> /// <returns>Document search engine</returns> public static DocumentSearch <TDocument> FilterIf <TDocument>(this DocumentSearch <TDocument> documentSearch, Func <bool> conditional, Expression <Func <TDocument, object> > fieldExpression, Action <SearchQuery <TDocument> > query, Action <IFilterParameter <TDocument> > instance = null) where TDocument : Document { Checker.IsNull(conditional); if (conditional.Invoke()) { documentSearch.Filter(fieldExpression, query, instance); } return(documentSearch); }
/// <summary> /// Create a filter parameter in commom case (field equals value, field with value in collection) /// </summary> /// <param name="documentSearch">Document search engine</param> /// <param name="conditional">Conditional to add parameter</param> /// <param name="fieldExpression">Expression used to find field name</param> /// <param name="values">Values to find</param> /// <returns>Document search engine</returns> public static DocumentSearch <TDocument> FilterIf <TDocument, TValue>(this DocumentSearch <TDocument> documentSearch, Func <bool> conditional, Expression <Func <TDocument, object> > fieldExpression, params TValue[] values) where TDocument : Document { Checker.IsNull(conditional); if (conditional.Invoke()) { documentSearch.Filter(fieldExpression, values); } return(documentSearch); }