Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Your post made me realize that custom string interpolation handlers from C# could probably be used to do injection-safe SQL querying (https://learn.microsoft.com/en-us/dotnet/csharp/advanced-top...). Makes me wonder whether scenarios like that were considered when they built that feature or if it's just a fun coincidence from making string interpolation extensible.


This is already a thing: https://learn.microsoft.com/en-us/ef/core/querying/sql-queri... although it uses an older API - https://learn.microsoft.com/en-us/dotnet/api/system.formatta...

Interpolated string handlers are a newer API made primarily with customization and efficiency of interpolation in mind. They are more complicated to implement and use but enable zero-cost and/or zero-allocation use cases and performing custom behavior on appending literals or data. They are also used to implement the default string interpolation handler and a few auxiliary ones like Append handler for a string builder which writes directly into it, bypassing intermediate string construction.

It's quite a mouthful to say though but very useful for advanced scenarios. Haven't seen any other language provide anything comparable.

See also: https://devblogs.microsoft.com/dotnet/string-interpolation-i...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: