打开它时执行 LINQPad 查询

Execute a LINQPad query on opening it

有没有一种方法可以让我在 LINQPad 中打开查询时执行查询并将我置于仅结果视图中?预期用例是在 LINQPad 中编写小型应用程序。我不想每次都按 F5 和 Ctrl+Shift+R。

这样做的动机是最近在 5.36 中发布的 RegEx 实用程序。这也是一个执行相同操作的脚本。

您可以使用 运行 脚本文件的参数启动 LINQPad from the command line

linqpad "path to file" -run

然后如果你添加行

System.Windows.Forms.SendKeys.SendWait("^+R");

作为Main中的第一行,代码将被隐藏。

请注意链接答案中有关在脚本末尾关闭 LINQPad 的建议。

我在下一个构建中添加了一个 Util.OpenQuery 方法:

public static Task<bool> OpenQuery (string queryPath, bool run = false,
                                    bool hideEditor = false, params object[] args)

然后您就可以从 Automator query:

void Main (System.Windows.Forms.Keys key, string currentQueryPath)
{
    if (key == (Keys.Shift | Keys.Control | Keys.Alt | Keys.F1))
        Util.OpenQuery (@"my query.linq", true, true);
}

这将允许您自动执行最多 12 个查询(使用热键 Alt+Shift+Ctrl+ [F1-F12])