|
StringExtensionsInterpolateT(String, T) Method
|
Applies string interpolation to the given format string at runtime.
Namespace: GSFAssembly: GSF.Core (in GSF.Core.dll) Version: 2.4.218-beta+101eee949414e414795e55a6e73d88938f0177b8
Syntax public static string Interpolate<T>(
this string format,
T parameters
)
JavaScript does not support generic types or methods.
View SourceParameters
- format String
- The format string to be interpolated.
- parameters T
- The parameters that can be referenced by the format string.
Type Parameters
- T
- The type of the object that defines the parameters for the format string.
Return Value
StringA 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 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.
See Also