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.172 -- Release Build+241430fabc9f8d815f226ef82f939af6835b2b48
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.

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