injecting imports when compiling
Rumbu
rumbu at rumbu.ro
Tue Dec 7 14:35:15 UTC 2021
On Tuesday, 7 December 2021 at 09:54:40 UTC, WebFreak001 wrote:
> Use cases:
> - small application templates/modes with common imports set
> (like std.stdio, std.conv, std.algorithm, std.array,
> std.format) so you can more easily and quickly prototype (C# 10
> / .NET 6 for example added this with implicit usings, though
> I'm not a fan because C# is just not that good at quick
> prototyping like D is)
>
Implicit usings are in fact a IDE feature workaround. Behind the
scenes, a hidden globalusings.g.cs file is created and added
silently to the existing project. The file contains several
```using global``` directives which are a new feature in C# 10.
You can manually write the same cs file, add it to the project
and obtain the same effect (as long as you are using C# 10).
The same approach will not work in D because in D each file is a
module, therefore the only chance is that the compiler read this
global imports from a configuration file and inject them into
each module.
On the other hand, placing a simple ```import std``` at the
beginning of your module will have the same effect.
More information about the Digitalmars-d
mailing list