I want to use string interpolation with a template, but I can't get it working. I have the following code:
public string Parse(string template, params dynamic[] objects) { return $"text text {objects[0].PropertyOne} {objects[0].PropertyThree} text text"; } This works fine, but I want to use the string template passed into the method, so it seems I need something like this:
public string Parse(string template, params dynamic[] objects) { return string.Format(template, objects[0].PropertyOne, objects[0].PropertyThree); } But I don't know how many parameters will be passed, or with which properties (hence the dynamic type). I need something that would work like this:
public string Parse(string template, params dynamic[] objects) { // template = "text text {objects[0].PropertyOne} {objects[0].PropertyThree} text text" return string.Format(template, objects); } Everywhere I look it says string interpolation is just an abstraction of string.Format, or that it uses string.Format in the end, so it sounds like something like this should be possible. Can I do what I aim for without reflection?
{0}and such), you cannot specify variables or expressions