StringExtensionsInterpolate(String, IEnumerableKeyValuePairString, Object) Method

Applies string interpolation to the given format string at runtime.

Definition

Namespace: Gemstone.StringExtensions
Assembly: Gemstone.Common (in Gemstone.Common.dll) Version: 1.0.128 -- Release Build+d050cfc5563c89a1188cc3c6b2d417530856f490
public static string Interpolate(
	this string format,
	IEnumerable<KeyValuePair<string, Object>> parameters
)

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