Including one .linq file inside another - please comment
I've just written a proposal for an upcoming new feature - referencing .linq files from other queries:
https://www.linqpad.net/LinqReference.aspx
Please let me know what you think!
https://www.linqpad.net/LinqReference.aspx
Please let me know what you think!
Comments
Any thoughts about sharing queryies using Upload to instant share function? Currently queries referencing My Extensions are not runnable stand alone. Perhaps a little warning dialog "It looks like you're referencing another query... which will not be included in the uploaded file" with "Do not show this again" would be enough, both for referenced .linq files as well as My Extensions.
If you were to reference several queries that all defined extension methods in a class with the same name (e.g., "Extensions"), you'd need to include the 'partial' keyword to avoid a collision.
Lack of nested references will hurt but I will take the 80/20 rule any day on this.
How would this method of referencing a query work with trying to initialize lots of (query) global variables?
Yes, it would work well in your CSV scenario. You'd declare your CSV variables as fields in the query, and populate them either with field initializers or in the OnStart() hook method.
forum.linqpad.net/discussion/1877/linqpad-6-for-net-core-3-preview-now-available
It now supports the #load directive, and should work well in your scenario.
Is there an F# way ?
With the following two files, running 2.linq produces the following error: 1.linq 2.linq If I change the extension method parameter to `this string something` instead of `this Something something`, the error goes away.
So it seems there's a problem using reference types in extension methods?
Meaning, if I load a script that itself has a load as well, will this work? I'm trying to create a series of scripts similar in structure to javascript modules and it doesn't seem to load beyond the first script.
A.linq: B.linq: C.linq: Attempting to run A.linq, I would get an error along the lines of:
This applies to all methods and types (with varying error messages).
A "workaround" I've found for now is to load all scripts depended on in the main script which I would rather not have to do (there's a lot of scripts).
Suppose the very simple case of a program query
A.linq
(A) hash-loading also a program queryB.linq
whereB.linq
(B) is some mini-library. What would here?- Will A's and B's imports get merged?
- Will A imports follow B imports or vice versa?
- Do imports include any static and aliasing imports?
- If B has an import then does A need it too?
- What happens to NuGet references between B and A? Do these also get merged as one set?
- Can B reference a NuGet package that's then used by A without A needing the same reference?
- If B and A reference different versions of the same package, which one will win?
Thanks!#load
) another inherits its imports except when the hash-loaded query is a Program query. Is this a bug or by-design behaviour? If it's the latter, what's the reason for the exception?With program-based queries, LINQPad creates a separate syntax tree, rather like including another .cs file in a project. This allows the loaded query to have its own imports, which avoids potential interference with the main query.
The hash-loading feature is a fantastic addition but I have hundreds of queries in production and I am trying to understand how to use hash-loading sensibly and for an optimal setup of mini-libraries. My fear is that someone changes a loaded query in a way that breaks all loading queries. The modification could be as simple as changing the query kind but it has far-reaching impacts for the loading query. You see, right now an empty statements-query can be used or abused to import namespaces as well as NuGet packages via hash-loading. Change it to a program query just to add some hooks and now you've broken the loading queries since they won't see the imports and references. It would be nice if LINQPad could help navigate the space of loading and loaded queries to avoid being surprised at run-time. I'm thinking:
- A menu option and shortcut to open all queries referenced in
- A menu option and shortcut to open all queries referencing a query open in the editor
Also, since a query with references is no longer a single unit of exchange and deployment, it would be nice to see LINQPad offer native support for exporting a query along with referenced ones as a#load
directives.zip
or.tar.gz
file (ideally both) as well as loading them back without going through the extra step of extracting those archives.Regarding NuGet packages and references, these are always imported into the host query regardless of whether the query is an expression, statement or program.