is it possible to call/reference functions in another query file beside MyExtensions in LinqPad?
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
}
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 oftest.linq
in this example.
From:
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
}
© 2022 - 2024 — McMap. All rights reserved.