I'm working on a system that gets templates from a database, then fills in values programmatically:
//using System.Runtime.CompilerServices;
var template = "Hello {0}"; // this string comes from the database
var name = "Joe";
var message = FormattableStringFactory.Create(template, new object[] { name });
Console.WriteLine(message);
This code sample works, but I can only use the numeric notation. I'd like to store the templates in the database in the interpolated string format, like this:
var template = "Hello {name}";
This throws a Run-time exception (line __): Input string was not in a correct format.
Is it possible to create an interpolated string from a string?
template,found tokens, data packed inDictionary<Token, TokenValue>into factory 3.) Iterate over found tokens and replace placeholders template.Replace(tokenItem, tokensData[tokenItem].Value)name, then human may screw up with letter and type it asnmae. I'd keep using old good{0}and will simply split long ones into several simpler, e.g. instead of "Good day {0}, would you like to do {1}" I'd make two sentences. And, well, you can still screw up even with{0}.