Search code examples
linqpad

is it possible to reference .linq file in LinqPad


is it possible to call/reference functions in another query file beside MyExtensions in LinqPad?


Solution

  • As of May 2019 it is possible now https://www.linqpad.net/LinqReference.aspx

    In LINQPad 6 and later, queries can reference other queries with the #load directive:

    #load "SomeOtherQuery.linq" // The #load directive must appear be at the top of the query

    Util.linq:

    void Main() { }
                    
    void OpenWithAssociatedApp (string file)
    {
        Process.Start (new ProcessStartInfo (file) { UseShellExecute = true });
    }
    
    class ConnectionStrings
    {
        public static string Test = "Data Source=.;Integrated Security=true;Database=test";
    }
    

    Some other query:

    #load "Util.linq"
    
    void Main()
    {
        File.WriteAllText ("foo.txt", "test");
    
        OpenWithAssociatedApp ("foo.txt");  // Calls OpenWithAssociatedApp in Util.linq
        ConnectionStrings.Test.Dump();      // Reads ConnectionStrings.Test in Util.linq
    }