/// <summary>
        /// Converts the <paramref name="query"/> to a <see cref="List{T}"/> of <see cref="TreeNode"/>
        /// </summary>
        /// <param name="query">The current MultiDocumentQuery</param>
        /// <param name="projection">Mapping function from <see cref="TreeNode"/> to <typeparamref name="TReturn" /></param>
        /// <param name="token">Optional cancellation token</param>
        /// <returns></returns>
        public static async Task <IList <TReturn> > ToListAsync <TReturn>(
            this MultiDocumentQuery query,
            Func <TreeNode, TReturn> projection,
            CancellationToken token = default)
        {
            var result = await query.GetEnumerableTypedResultAsync(cancellationToken : token);

            return(result.Select(projection).ToList());
        }
Exemple #2
0
        protected async Task <IEnumerable <TPage> > GetPagesOfMultipleTypesAsync(
            IEnumerable <string> types,
            SiteCulture culture,
            Action <MultiDocumentQuery>?filter = default)
        {
            MultiDocumentQuery query = GetQueryForMultipleTypes(types, culture, filter);

            return((await query
                    .GetEnumerableTypedResultAsync())
                   .Select(page => page as TPage)
                   .Where(page => page != null) !);
        }
        /// <summary>
        /// Converts the <paramref name="query"/> to a <see cref="List{T}"/> of <see cref="TreeNode"/>
        /// </summary>
        /// <param name="query">The current MultiDocumentQuery</param>
        /// <param name="token">Optional cancellation token</param>
        /// <returns></returns>
        public static async Task <IList <TreeNode> > ToListAsync(this MultiDocumentQuery query, CancellationToken token = default)
        {
            var result = await query.GetEnumerableTypedResultAsync(cancellationToken : token);

            return(result.ToList());
        }
        /// <summary>
        /// Returns the first item of the <paramref name="query"/> as a <see cref="TreeNode"/> and null if no items were returned.
        /// </summary>
        /// <param name="query">The current MultiDocumentQuery</param>
        /// <param name="token">Optional cancellation token</param>
        /// <returns></returns>
        public static async Task <TreeNode?> FirstOrDefaultAsync(this MultiDocumentQuery query, CancellationToken token = default)
        {
            var result = await query.GetEnumerableTypedResultAsync(cancellationToken : token);

            return(result?.FirstOrDefault());
        }