private TResult ApplyScalarMethods <TResult, TDocument>(LuceneQuery query, object processedResults, ITopDocs results) { var baseMethod = typeof(LinqToLuceneIndex <TItem>).GetMethod("ApplyScalarMethods", BindingFlags.Instance | BindingFlags.NonPublic).MakeGenericMethod(typeof(TResult), typeof(TDocument)); return((TResult)baseMethod.Invoke(this, new[] { query, processedResults, results })); }
/* * THESE METHODS ARE A TOTAL HACK * They exist to work around a bug in Sitecore (7.x-8.0 at least) where it uses private reflection * in such a way that it breaks all derived classes of LinqToLuceneIndex when GetResults() is called * on the queryable (#4 on GitHub) * * These basically act as proxies so the private reflection in Sitecore hits these methods, * which then reflect the call down to the base class' private method as is expected. * * Source of hack: the Execute() method on the base class doing this: * MethodInfo methodInfo1 = this.GetType().GetMethod("ApplySearchMethods", BindingFlags.Instance | BindingFlags.NonPublic).MakeGenericMethod(type); * MethodInfo methodInfo2 = this.GetType().GetMethod("ApplyScalarMethods", BindingFlags.Instance | BindingFlags.NonPublic).MakeGenericMethod(typeof (TResult), type); * * The this.GetType() cause it to look for the private methods on any derived classes, where they do not exist. */ private object ApplySearchMethods <TElement>(LuceneQuery query, ITopDocs searchHits) { var baseMethod = typeof(LinqToLuceneIndex <TItem>).GetMethod("ApplySearchMethods", BindingFlags.Instance | BindingFlags.NonPublic).MakeGenericMethod(typeof(TElement)); return(baseMethod.Invoke(this, new object[] { query, searchHits })); }