4 ms·
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.co
by kevingadd 2y ago
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-topics/performance/interpolated-string-handler 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.
- neonsunset 2y agoThis is already a thing: https://learn.microsoft.com/en-us/ef/core/querying/sql-queries 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.formattablestring 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-in-c-10-and-net-6/ https://devblogs.microsoft.com/dotnet/string-interpolation-i...