|
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: FormattableString
**
**
** Purpose: implementation of the FormattableString
** class.
**
===========================================================*/
namespace System
{
/// <summary>
/// A composite format string along with the arguments to be formatted. An instance of this
/// type may result from the use of the C# or VB language primitive "interpolated string".
/// </summary>
public abstract class FormattableString : IFormattable
{
/// <summary>
/// The composite format string.
/// </summary>
public abstract string Format { get; }
/// <summary>
/// Returns an object array that contains zero or more objects to format. Clients should not
/// mutate the contents of the array.
/// </summary>
public abstract object[] GetArguments();
/// <summary>
/// The number of arguments to be formatted.
/// </summary>
public abstract int ArgumentCount { get; }
/// <summary>
/// Returns one argument to be formatted from argument position <paramref name="index"/>.
/// </summary>
public abstract object GetArgument(int index);
/// <summary>
/// Format to a string using the given culture.
/// </summary>
public abstract string ToString(IFormatProvider formatProvider);
string IFormattable.ToString(string ignored, IFormatProvider formatProvider)
{
return ToString(formatProvider);
}
/// <summary>
/// Format the given object in the invariant culture. This static method may be
/// imported in C# by
/// <code>
/// using static System.FormattableString;
/// </code>.
/// Within the scope
/// of that import directive an interpolated string may be formatted in the
/// invariant culture by writing, for example,
/// <code>
/// Invariant($"{{ lat = {latitude}; lon = {longitude} }}")
/// </code>
/// </summary>
public static string Invariant(FormattableString formattable)
{
if (formattable == null)
{
throw new ArgumentNullException("formattable");
}
return formattable.ToString(Globalization.CultureInfo.InvariantCulture);
}
public override string ToString()
{
return ToString(Globalization.CultureInfo.CurrentCulture);
}
}
}
|