StringExtensionsInterpolateT(String, T) Method
Applies string interpolation to the given format string at runtime.
Namespace: Gemstone.StringExtensionsAssembly: Gemstone.Common (in Gemstone.Common.dll) Version: 1.0.128 -- Release Build+d050cfc5563c89a1188cc3c6b2d417530856f490
public static string Interpolate<T>(
this string format,
T parameters
)
<ExtensionAttribute>
Public Shared Function Interpolate(Of T) (
format As String,
parameters As T
) As String
public:
[ExtensionAttribute]
generic<typename T>
static String^ Interpolate(
String^ format,
T parameters
)
JavaScript does not support generic types or methods.
- format String
- The format string to be interpolated.
- parameters T
- The parameters that can be referenced by the format string.
- T
- The type of the object that defines the parameters for the format string.
String
A copy of
format in which the format items have been replaced by the string representation of the
corresponding
parameters.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).
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.