Is it possible to include code from one .linq file in a different .linq file during compilation?

I'm interested in building some diagnostic tools around LinqPad.

The idea being we would have a library of different .linq files for different purposes.
Like any good engineer's we would like to be able to reduce code duplication if possible.

I would like to be able to factor out different parts of the code we would call into seperate .linq files and be able to later #include or something equivelant to have the code in that file included in compilation with my current "query".

I realize we could factor this common code into a library which we include in our queries, however I'm still interested if the above is possible?

Comments

  • The only way to do this at present is to add common code to the 'My Extensions' query. Any types that you define here are available to all queries.

    There's a popular UserVoice request for including one .LINQ file within another. It's not a simple thing to implement well, though, because compile-time or run-time errors would need to somehow indicate where in the included code the problem has occurred. A piece of included code that works perfectly on its own may fail to compile when included in another query for many reasons, such as conflicting identifier names, difference namespace/assembly imports, etc.
  • While I appreciate (a lot!) your desired to always do things the best way possible, I think something would be a lot better than nothing in this case.

    I have some fairly complicated linq to define some variables that I then have multiple statement queries based on these variables to run. It would be much easier if I didn't have to update each query individually when I discover an issue with a base variable definition, even if error handling wasn't ideal. Pointing the error at the e.g. #include line would be good enough for now.
  • I think there should be something like an #load command like in F# for C# scripts:
    Interactive Programming with F#
  • Unless the duplicated code makes calls into Dump() or other LINQPad specifics, then you can use standard dev IDE's to compile them as separate dll's and then include them in your linq queries.

    But, yes, a #include of sorts that made any number of external linq files behave as myExtensions for the query would be very much welcome.
  • Actually, code that you compile in Visual Studio can include calls to Dump or other LINQPad-specifics. Just reference LINQPad.exe.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!