Improve Dictionary TryGetValue size/perfomance (dotnet/coreclr#27195)
[mono-project.git] / netcore / System.Private.CoreLib / shared / System / FormattableString.cs
blob73b1981cd718938e0a1672754c59b0259d663bee
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 /*============================================================
6 **
7 **
8 **
9 ** Purpose: implementation of the FormattableString
10 ** class.
12 ===========================================================*/
14 namespace System
16 /// <summary>
17 /// A composite format string along with the arguments to be formatted. An instance of this
18 /// type may result from the use of the C# or VB language primitive "interpolated string".
19 /// </summary>
20 public abstract class FormattableString : IFormattable
22 /// <summary>
23 /// The composite format string.
24 /// </summary>
25 public abstract string Format { get; }
27 /// <summary>
28 /// Returns an object array that contains zero or more objects to format. Clients should not
29 /// mutate the contents of the array.
30 /// </summary>
31 public abstract object?[] GetArguments();
33 /// <summary>
34 /// The number of arguments to be formatted.
35 /// </summary>
36 public abstract int ArgumentCount { get; }
38 /// <summary>
39 /// Returns one argument to be formatted from argument position <paramref name="index"/>.
40 /// </summary>
41 public abstract object? GetArgument(int index);
43 /// <summary>
44 /// Format to a string using the given culture.
45 /// </summary>
46 public abstract string ToString(IFormatProvider? formatProvider);
48 string IFormattable.ToString(string? ignored, IFormatProvider? formatProvider)
50 return ToString(formatProvider);
53 /// <summary>
54 /// Format the given object in the invariant culture. This static method may be
55 /// imported in C# by
56 /// <code>
57 /// using static System.FormattableString;
58 /// </code>.
59 /// Within the scope
60 /// of that import directive an interpolated string may be formatted in the
61 /// invariant culture by writing, for example,
62 /// <code>
63 /// Invariant($"{{ lat = {latitude}; lon = {longitude} }}")
64 /// </code>
65 /// </summary>
66 public static string Invariant(FormattableString formattable)
68 if (formattable == null)
70 throw new ArgumentNullException(nameof(formattable));
73 return formattable.ToString(Globalization.CultureInfo.InvariantCulture);
76 /// <summary>
77 /// Format the given object in the current culture. This static method may be
78 /// imported in C# by
79 /// <code>
80 /// using static System.FormattableString;
81 /// </code>.
82 /// Within the scope
83 /// of that import directive an interpolated string may be formatted in the
84 /// current culture by writing, for example,
85 /// <code>
86 /// CurrentCulture($"{{ lat = {latitude}; lon = {longitude} }}")
87 /// </code>
88 /// </summary>
89 public static string CurrentCulture(FormattableString formattable)
91 if (formattable == null)
93 throw new ArgumentNullException(nameof(formattable));
96 return formattable.ToString(Globalization.CultureInfo.CurrentCulture);
99 public override string ToString()
101 return ToString(Globalization.CultureInfo.CurrentCulture);