Click or drag to resize

StringExtensionsInterpolate(String, IEnumerableKeyValuePairString, Object) Method

Applies string interpolation to the given format string at runtime.

Namespace: GSF
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.218-beta+101eee949414e414795e55a6e73d88938f0177b8
Syntax
public static string Interpolate(
	this string format,
	IEnumerable<KeyValuePair<string, Object>> parameters
)
View Source

Parameters

format  String
The format string to be interpolated.
parameters  IEnumerableKeyValuePairString, Object
The parameters that can be referenced by the format string.

Return Value

String
A copy of format in which the format items have been replaced by the string representation of the corresponding parameters.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type String. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks

This overload is intended to be used for scenarios in which the parameters available to the format string are stored in a DictionaryTKey, TValue or ExpandoObject. Note that dynamic variables cannot be used when calling extension functions.

C#
string format = "{hello} {world}!";
dynamic parameters = new ExpandoObject();
parameters.hello = "Hello";
parameters.world = "World";

Console.WriteLine(format.Interpolate(parameters));                  // This raises a compiler error
Console.WriteLine(format.Interpolate((ExpandoObject)parameters);    // This is okay
Console.WriteLine(StringExtensions.Interpolate(format, parameters); // This is also okay
See Also