is it possible to reference .linq file in LinqPad
Asked Answered
D

3

6

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

Decolorant answered 4/12, 2012 at 0:29 Comment(1)
Both of the answers were, effectively, written by Joe Albahari, the author of LINQPad, but six years apart!Centerboard
U
2

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
}
Utas answered 13/11, 2023 at 6:44 Comment(0)
C
3

You can call one script from another:

Another way to combine scripts is to dynamically execute one script from another. The Util.Run method does exactly that, and is useful in both interactive and command-line scenarios:

string htmlResult = Util.Run ("test.linq", QueryResultFormat.Html).AsString();

Note: If you feed Util.Run a relative path, it will resolve it relative to the 'My Queries' directory rather than the current directory. You can switch its behavior by specifying .\test.linq instead of test.linq in this example.

From:

Centerboard answered 9/9, 2018 at 4:22 Comment(0)
U
2

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
}
Utas answered 13/11, 2023 at 6:44 Comment(0)
S
1

No, this isn't possible right now.

Staley answered 4/12, 2012 at 3:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.