Does this finally allow reading string literals from files and include them into the binaries? I've seen a Go project that was heavily using https://pkg.go.dev/embed for loading some template files, and got a bit jealous. Back in the days of .NET Framework it was common to compile file contents into resource files, but it was always quite cumbersome.
Comptime – C# meta-programming with compile-time code generation and evaluation
41–50 of 71 posts
Re: Comptime – C# meta-programming with compile-time code generation and evaluation
#42Does this finally allow reading string literals from files and include them into the binaries? I've seen a Go project that was heavily using https://pkg.go.dev/embed for loading some template files, and got a bit jealous. Back in the days of .NET Framework it was common to compile file contents into resource files, but it was always quite cumbersome.
Then you can read that file from the assembly with: assembly.GetManifestResourceStream
I'm not sure what's awkward about that, but it's nothing new.Discoverability for this is in visual studio, if you go to file properties there's a drop-down where you choose between Content, EmbeddedResource, Ignore, etc.
That determines what happens in compile, whether it is copied to output directory, compiled into the binary, etc.
Re: Comptime – C# meta-programming with compile-time code generation and evaluation
#43Does this finally allow reading string literals from files and include them into the binaries? I've seen a Go project that was heavily using https://pkg.go.dev/embed for loading some template files, and got a bit jealous. Back in the days of .NET Framework it was common to compile file contents into resource files, but it was always quite cumbersome.
Can't you already do that with embedded resources?
In modern code I don't see them that often anymore.
Re: Comptime – C# meta-programming with compile-time code generation and evaluation
#44Does this finally allow reading string literals from files and include them into the binaries? I've seen a Go project that was heavily using https://pkg.go.dev/embed for loading some template files, and got a bit jealous. Back in the days of .NET Framework it was common to compile file contents into resource files, but it was always quite cumbersome.
C# / .NET has always had that abililty. Then you can read that file from the assembly with: assembly.GetManifestResourceStream I'm not sure what's awkward about that, but it's nothing new. Discoverability for this is in visual studio, if you go to file properties there's a drop-down where you choose between Content, EmbeddedResource, Ignore, etc. That determines what happens in compile, whether it is copied to output…
Re: Comptime – C# meta-programming with compile-time code generation and evaluation
#45I started using C# recently for a hobby project writing a game engine on top of Monogame, and I have been very surprised at how nice of a language C# is to use. It has a clean syntax, decent package management, and basically every language feature I regularly reach for except algebraic data types, which are probably coming eventually. I think the association of .NET to Microsoft tarnished my expectations.
Modern C# and .NET are great. It still suffers from the bad reputation of the Windows-only .NET Framework. It's still a quite heavy platform with a lot of features, but the .NET team invested a lot of time to make it more approachable recently. With top level Programs and file-based apps[1] it can be used as a scripting language now, just add a shebang (#!/usr/local/share/dotnet/dotnet run) to the first line and make…
Re: Comptime – C# meta-programming with compile-time code generation and evaluation
#46I started using C# recently for a hobby project writing a game engine on top of Monogame, and I have been very surprised at how nice of a language C# is to use. It has a clean syntax, decent package management, and basically every language feature I regularly reach for except algebraic data types, which are probably coming eventually. I think the association of .NET to Microsoft tarnished my expectations.
Sometimes I wonder if the .NET department is totally separated from the rest of Microsoft. Microsoft is so bad on all fronts I stopped using everything that has to do with it. Windows, Xbox, the Microsoft account experience, the Microsoft store, for me it has been one big trip of frustration.
Re: Comptime – C# meta-programming with compile-time code generation and evaluation
#47Earlier quoted context omitted.
Modern C# and .NET are great. It still suffers from the bad reputation of the Windows-only .NET Framework. It's still a quite heavy platform with a lot of features, but the .NET team invested a lot of time to make it more approachable recently. With top level Programs and file-based apps[1] it can be used as a scripting language now, just add a shebang (#!/usr/local/share/dotnet/dotnet run) to the first line and make…
Also, if you compile Ahead Of Time (AOT) you can cut down on the features and get basically as small a subset as you want of the libraries. IMHO C# and dotnet are really starting to become very impressive.
The default runtime and JIT are fine for most use cases.
Re: Comptime – C# meta-programming with compile-time code generation and evaluation
#48I started using C# recently for a hobby project writing a game engine on top of Monogame, and I have been very surprised at how nice of a language C# is to use. It has a clean syntax, decent package management, and basically every language feature I regularly reach for except algebraic data types, which are probably coming eventually. I think the association of .NET to Microsoft tarnished my expectations.
I love C# and .NET and use it every day. Sometimes I wonder if the .NET department is totally separated from the rest of Microsoft. Microsoft is so bad on all fronts I stopped using everything that has to do with it. Windows, Xbox, the Microsoft account experience, the Microsoft store, for me it has been one big trip of frustration.
.NET seems to be somewhere close to Azure, but now far away from Windows or the business applications (Office/Teams, Dynamics, Power Platform). Things like GitHub, LinkedIn or Xbox seem to be de facto separate companies.
Edit: .NET used to be tied closely to Windows, which gave it the horrible reputation. The dark age of .NET ;)
Re: Comptime – C# meta-programming with compile-time code generation and evaluation
#49Earlier quoted context omitted.
Immutable collections exit, they were just added later. See System.Collections.Immutable: https://learn.microsoft.com/en-us/dotnet/api/system.collecti...
I do a lot of .NET programming, and I've never seen them getting used. :O
Re: Comptime – C# meta-programming with compile-time code generation and evaluation
#50C# meta programming game is strong. Source generators are :chefs_kiss:
I love (and heavily use) source generators, but the development experience is godawful. Working with the raw Roslyn types is painful at best and this is compounded by them having to be written against .NET Standard, severely limiting the use of newer .NET functionality. Eventually I want to write a good baseline library to use for my source generators -- simplifying finding definitions with attributes, mapping types…
I sometimes generate code from plain CLI projects (avoiding source generators altogether), as whole debugging and DX is so much better.