Search code examples
linqpad

Execute a LINQPad query on opening it


Is there a way by which, when I open a query in LINQPad, it executes it and puts me in the result-only view? The intended use case for this is to write small applications within LINQPad. I don't want to hit F5 and Ctrl+Shift+R every time.

The motivation for this is the recently released RegEx utility in 5.36. This is also a script that does the same.


Solution

  • I've added an Util.OpenQuery method to the next build:

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

    You'll then be able to call this from the 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);
    }
    

    This will allow you to automate up to 12 queries (with hotkeys Alt+Shift+Ctrl+ [F1-F12])