<ExtensionAttribute>
Public Shared Function Interpolate(Of T) (
format As String,
parameters As T
) As Stringpublic:
[ExtensionAttribute]
generic<typename T>
static String^ Interpolate(
String^ format,
T parameters
)This overload uses reflection to obtain the name and value of parameters' properties to make those available to the interpolated format string by name. This can be used with user-defined types, but is mainly intended to be used with anonymous types.
string format = "{hello} {world}!";
var parameters = new { hello = "Hello", world = "World" };
Console.WriteLine(format.Interpolate(parameters));
If parameters can be safely cast to IEnumerable{KeyValuePair{string, object}}, this function
will skip the reflection and call Interpolate(String, IEnumerableKeyValuePairString, Object) directly.