I suggest you ...

include another .cs file(s) in a .linq file

in "C# Program" mode:

void Main()
// Define other methods and classes here

#include MyClass.cs // <--- something like this

So that we can have MyClass defined in another file (MyClass.cs) and just include it instead of copy&pasting the code. This would allow better code separation and re-use.

733 votes
Sign in
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    anonymous shared this idea  ·   ·  Admin →


    Sign in
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      • Alan Hemmings commented  · 

        I believe that referencing linqpad files makes more sense that cs files, e.g.
        #include MySettings.linq
        #include MyDTOs.linq

      • Alan Hemmings commented  · 

        This is never going to be done.

        Perhaps what we need to do, is ask Joe ... "How much?" and we start a kickstarter campaign to make it happen?


        Happy to pay an extra licence for being able to use this at work across multiple scripts. That would ensure that random kiddy developers who are using Linqpad for playing with coding don't use the mutli-script version and only serious teams would purchase the team-support upgrade.

        cmon, let's make this happen!

      • John Stevens commented  · 

        I have wanted to go beyond the "My Extensions" and found a work around to this issue by creating a LINQPad script that lets you choose another LINQPad script to compile into an assembly, if anyone is interested. You have to format the query a specific way, but it's better than nothing.

      • Franklin Ross commented  · 

        As Erling mentioned, would it be easier to just compile the referenced query and add it as a reference behind the scenes somewhere? Just add 'using static MyQueries.QueryName' on the references tab or something. This would import all static members and types, which would achieve the same thing. I know Joe Albahari has mentioned there are plenty of complicated issues with a C style #include, but for the most part I just want this to get at types I can reuse across queries.

      • Dev commented  · 

        I think I have missed this facility frequently. I would like to include a class from my solution so I can quickly test it. Or write new code with correct separation so it can be directly pasted or exported for including in a visual studio solution.
        Also I would like to add resources to a LINQ file, like xml, json etc.

      • Adrian Hesketh commented  · 

        I think an export to Visual Studio might be better. Most of my projects start out as LinqPad scripts, then I get too many classes in one .linq file and then have to create a VS project and copy / paste the code, and sort out nuget packages / dependencies.

      • andy qi commented  · 

        #include "myotherscript.linq"
        Good idear ! That's what I need.

      • Alan Hemmings commented  · 

        Id rather include another .linq file instead of a .cs, that way if the referenced file was in program format, then the main for the included file will be ingnored, and I could use the main (of the included linq) file, as a means of running some simple tests when working on the script.To edit the included file, I'd simply double click it, and make changes, run some code as a test, and hit save, bosh...done.

      • Andreas Vilinski commented  · 

        c# is boring. better make support for #include MyModule.fs

      • Alan Hemmings commented  · 

        I just hit a brick wall trying to use linqpad instead of powershell and nant as a built tool, and need to be able to either pass DTO's to a script, (assuming the DTO is in a referenced assembly), or I need to be able to include a script, so that I don't have to repeat myself. With this feature I could use linqpad as a build tool, currently as it stands, I cannot use it for any resonable size project. I could replace powershell, Ruby, Nant ... all with Linqpad, please please please add this feature! ;-D (Util.Run is a good start, but is buggy. Include makes far more sense, alternatively be able to pass proper objects between scripts, so that we don't have to parse strings to objects all the time in Main(string[] args). Linqpad is soooo close to being able to be more useful that powershell!

      • raboof commented  · 

        This is an excellent idea but the implementation would be even cooler if one could reference stand-alone source files just like one can add references to assemblies and NuGet packages. The reference should be in the form of a URL (which could use the file scheme for local files and http/https for remote ones) so one can reference files directly out on the web and they get downloaded and become part of the current query. As long as a source file can be identified by a URL (thinking gists here especially), it should be reference-able. The remote files should be cached in the .linq file when saved for being able to run offline too. Finally, there would be a dialog box that allows one to manage those references and download updates! The cherry on top of all this would be support for NuGet packages that contain source files as content!

      • ZEE commented  · 

        Been too long to have the "include" option available...
        If it's done via adding one more tab to the "query properties" dialog (F4) it does not seem to hard to be done... ?what's holding back this feature???

        I'll suggest also to have 2 panes,,, one for pre-inclusion and one for pós-inclusion...


      • Brandon Bernard commented  · 

        I agree, as fantastic as LINQPad is, this is a significant feature lacking.... within 3 days of purchasing a full license copy I'm Googleing for how to do this exactly.... link to libs or re-usable classes would be far more useful than the MyExtensions.linq file that isn't even stored with all of the other Queries so it's pretty useless to rely on this in Code snippets that ARE shared...

        A simple syntax or GUI as others have mentioned, would be Awesome.

        #Include ../MyQueryLibs/LINQ2Xml.cs (or .linq if required)....

      • Gabe Williamson commented  · 

        It would be neat if we could "import" other tabs. Or if something like Program or Statement tabs were always on-the-fly compiled into referenceable dlls that we could import with a linqpad namespace.

      • Maxwell Bloch commented  · 

        Integrate this with the suggested social feature.
        Use comment pre-parsing to implement
        // #include localFile.cs
        // #include gist:12345678

      • Anonymous commented  · 

        Ditto that, this thing is almost the killer app, just gets messing having to dup everything in the same file

      • ZEE commented  · 

        YES... too long since I suggested this too...
        Of course for VB, SQL, etc. too...
        The best way to do it is in the query preferences add one more tab to delclare what include files (.linq) this snippet process...
        Also a section in this tab to declare some .linq files that are included in all the projects (by type, of course... We dont want to include a C# file in a SQL snippet... that is another war...)

      ← Previous 1

      Feedback and Knowledge Base