summaryrefslogtreecommitdiff
path: root/src/mscorlib/shared/System/FormattableString.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/shared/System/FormattableString.cs')
-rw-r--r--src/mscorlib/shared/System/FormattableString.cs81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/mscorlib/shared/System/FormattableString.cs b/src/mscorlib/shared/System/FormattableString.cs
new file mode 100644
index 0000000000..6369363b5d
--- /dev/null
+++ b/src/mscorlib/shared/System/FormattableString.cs
@@ -0,0 +1,81 @@
+// 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.
+
+/*============================================================
+**
+**
+**
+** 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(nameof(formattable));
+ }
+
+ return formattable.ToString(Globalization.CultureInfo.InvariantCulture);
+ }
+
+ public override string ToString()
+ {
+ return ToString(Globalization.CultureInfo.CurrentCulture);
+ }
+ }
+}