Fix IDE0025 (use expression body for properties)
[mono-project.git] / netcore / System.Private.CoreLib / shared / System / Runtime / CompilerServices / FormattableStringFactory.cs
blobc08ebaee06160190daff4580cbcb88910d6a09d5
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 FormattableStringFactory
10 ** class.
12 ===========================================================*/
14 namespace System.Runtime.CompilerServices
16 /// <summary>
17 /// A factory type used by compilers to create instances of the type <see cref="FormattableString"/>.
18 /// </summary>
19 public static class FormattableStringFactory
21 /// <summary>
22 /// Create a <see cref="FormattableString"/> from a composite format string and object
23 /// array containing zero or more objects to format.
24 /// </summary>
25 public static FormattableString Create(string format, params object?[] arguments)
27 if (format == null)
29 throw new ArgumentNullException(nameof(format));
32 if (arguments == null)
34 throw new ArgumentNullException(nameof(arguments));
37 return new ConcreteFormattableString(format, arguments);
40 private sealed class ConcreteFormattableString : FormattableString
42 private readonly string _format;
43 private readonly object?[] _arguments;
45 internal ConcreteFormattableString(string format, object?[] arguments)
47 _format = format;
48 _arguments = arguments;
51 public override string Format => _format;
52 public override object?[] GetArguments() { return _arguments; }
53 public override int ArgumentCount => _arguments.Length;
54 public override object? GetArgument(int index) { return _arguments[index]; }
55 public override string ToString(IFormatProvider? formatProvider) { return string.Format(formatProvider, _format, _arguments); }