I want to interpolate not only the tokens in a string, but also the format itself. Here's an example using string.Format which loads the format string from a local variable:
object boxedDate = DateTime.Today;
var dateFormat = "MM-dd-yyyy";
var dateString = string.Format($"{{0:{dateFormat}}}", boxedDate);
With the interpolated string syntax, though, it seems that the format portion of the string is purely literal. Conceptually, I'd like to do something like this:
dateString = $"{boxedDate:{dateFormat}}";
Doesn't work, of course. I know that I could unbox the datetime and invoke .ToString() like this:
dateString = $"{((DateTime)boxedDate).ToString(dateFormat)}";
...but that requires me to know the type at runtime. This could be a decimal, integer, date, etc.
It's not a deal breaker or anything. I could always still use string.Format if there's no actual way to do this with interpolated string syntax.