示例#1
0
        /// <summary>
        ///     Simplifies the <c>while</c>, <see cref="IResultCursor.FetchAsync" /> pairing, allowing a called to just use a
        ///     <see cref="foreach" />.
        /// </summary>
        /// <remarks>
        ///     You will want <typeparamref name="T" /> to be one of the ones that the <see cref="IDriver" /> can handle, i.e.
        ///     <see cref="INode" /> etc.<br />
        ///     NB. If you want to pull more than just one property from the <paramref name="cursor" />, don't use this method, use
        ///     <see cref="GetRecords" /> instead.
        /// </remarks>
        /// <typeparam name="T">The <see cref="Type" /> to try to get the <paramref name="identifier" /> as.</typeparam>
        /// <param name="cursor">The <see cref="IResultCursor" /> instance to read from.</param>
        /// <param name="identifier">The identifier to pull out from.</param>
        /// <returns><c>yield</c>s the <typeparamref name="T" /> retrieved from the <paramref name="cursor" />.</returns>
        public static async IAsyncEnumerable <T> GetContent <T>(this IResultCursor cursor, string identifier)
        {
            Ensure.That(cursor).IsNotNull();
            Ensure.That(identifier).IsNotNullOrWhiteSpace();

            var fetched = await cursor.FetchAsync();

            while (fetched)
            {
                yield return(cursor.GetValue <T>(identifier));

                fetched = await cursor.FetchAsync();
            }
        }