public static TBuilder SortAsVariant <TBuilder, TRequest, TEntity, TSwitch>( this RequestEntityConfigBuilderCommon <TRequest, TEntity, TBuilder> config, Func <TRequest, TSwitch> getSwitchValue, Action <SwitchSortBuilder <TRequest, TEntity, TSwitch> > configure) where TEntity : class where TSwitch : class where TBuilder : RequestEntityConfigBuilderCommon <TRequest, TEntity, TBuilder> { var builder = new SwitchSortBuilder <TRequest, TEntity, TSwitch>(getSwitchValue); configure(builder); return(config.SetSorter(builder.Build())); }
/// <summary> /// Configures how a query's results should be ordered. /// See the docs for more information on "Variant Sorting". /// </summary> public TBuilder SortAsVariant <TSwitch>( string switchProperty, Action <SwitchSortBuilder <TRequest, TEntity, TSwitch> > configure) where TSwitch : class { var requestParam = Expression.Parameter(typeof(TRequest), "r"); var requestProp = Expression.PropertyOrField(requestParam, switchProperty); var readPropExpr = Expression.Lambda <Func <TRequest, TSwitch> >(requestProp, requestParam); var builder = new SwitchSortBuilder <TRequest, TEntity, TSwitch>(readPropExpr.Compile()); configure(builder); var sorterFactory = builder.Build(); return(SetSorter(sorterFactory)); }