As mentioned in the comments, line interpolation works in this case, since the whole new compiler does the conversion of the expression to an "equivalent string. Format call" at compile time.
From https://msdn.microsoft.com/en-us/magazine/dn879355.aspx
String interpolation is converted at compile time to invoke an equivalent string. Format the call. This leaves the localization support in place as before (although still with traditional format strings) and does not introduce any post-compiling code injection through the strings.
FormattableString is a new class that allows you to check string interpolation before rendering so you can check values ββand protect against injection.
// this does not require .NET 4.6 DateTime now = DateTime.Now; string s = $"Hour is {now.Hour}"; Console.WriteLine(s); //Output: Hour is 13 // this requires >= .NET 4.6 FormattableString fs = $"Hour is {now.Hour}"; Console.WriteLine(fs.Format); Console.WriteLine(fs.GetArgument(0)); //Output: Hour is {0} //13
source share