コード例 #1
0
        /// <summary>
        /// Allow the caller to specify an action that has access to the full query text at the point
        /// at which this method is called. Useful for custom logging of the query.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static DocumentQuery <TNode> TapQueryText <TNode>(this DocumentQuery <TNode> query, Action <string> action)
            where TNode : TreeNode, new()
        {
            action(query.GetFullQueryText());

            return(query);
        }
        /// <summary>
        /// Prints the provided query's full materialized query text using <see cref="LoggerExtensions.LogDebug(ILogger, string, object[])"/>
        /// </summary>
        /// <param name="query">The current DocumentQuery</param>
        /// <param name="logger">The logger used to output the query</param>
        /// <param name="queryName">Optional Name for the query that will denote in the output where this specific query starts and ends.
        /// If no value is supplied, the filename containing the calling method will be used. If null or an empty string is supplied, name of the generic <see cref="{TNode}" /> will be used.
        /// </param>
        /// <returns></returns>
        public static DocumentQuery <TNode> LogQuery <TNode>(this DocumentQuery <TNode> query, ILogger logger, [CallerFilePath] string queryName = "")
            where TNode : TreeNode, new()
        {
            queryName = string.IsNullOrWhiteSpace(queryName)
                ? typeof(TNode).Name
                : queryName;

            logger.LogDebug("{queryName} {queryText}", queryName, query.GetFullQueryText());

            return(query);
        }
        /// <summary>
        /// Prints the provided query's full materialized query text using <see cref="Debug.WriteLine(object?)"/>
        /// </summary>
        /// <param name="query">The current DocumentQuery</param>
        /// <param name="queryName">Optional Name for the query that will denote in the output where this specific query starts and ends.
        /// If no value is supplied, the filename containing the calling method will be used. If null or an empty string is supplied, name of the generic <see cref="{TNode}" /> will be used.
        /// </param>
        /// <returns></returns>
        public static DocumentQuery <TNode> DebugQuery <TNode>(this DocumentQuery <TNode> query, [CallerFilePath] string queryName = "")
            where TNode : TreeNode, new()
        {
            queryName = string.IsNullOrWhiteSpace(queryName)
                ? typeof(TNode).Name
                : queryName;

            Debug.WriteLine(Environment.NewLine);
            Debug.WriteLine($"~~~ BEGIN [{queryName}] QUERY ~~~");
            Debug.WriteLine(Environment.NewLine);

            Debug.WriteLine(Environment.NewLine);
            Debug.WriteLine(query.GetFullQueryText());
            Debug.WriteLine(Environment.NewLine);

            Debug.WriteLine(Environment.NewLine);
            Debug.WriteLine($"~~~ END [{queryName}] QUERY ~~~");
            Debug.WriteLine(Environment.NewLine);

            return(query);
        }