// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. /*============================================================ ** ** Class: FormattableString ** ** ** Purpose: implementation of the FormattableString ** class. ** ===========================================================*/ namespace System { /// /// 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". /// public abstract class FormattableString : IFormattable { /// /// The composite format string. /// public abstract string Format { get; } /// /// Returns an object array that contains zero or more objects to format. Clients should not /// mutate the contents of the array. /// public abstract object[] GetArguments(); /// /// The number of arguments to be formatted. /// public abstract int ArgumentCount { get; } /// /// Returns one argument to be formatted from argument position . /// public abstract object GetArgument(int index); /// /// Format to a string using the given culture. /// public abstract string ToString(IFormatProvider formatProvider); string IFormattable.ToString(string ignored, IFormatProvider formatProvider) { return ToString(formatProvider); } /// /// Format the given object in the invariant culture. This static method may be /// imported in C# by /// /// using static System.FormattableString; /// . /// Within the scope /// of that import directive an interpolated string may be formatted in the /// invariant culture by writing, for example, /// /// Invariant($"{{ lat = {latitude}; lon = {longitude} }}") /// /// 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); } } }