1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
4 /*============================================================
6 ** Class: FormattableStringFactory
9 ** Purpose: implementation of the FormattableStringFactory
12 ===========================================================*/
13 namespace System.Runtime.CompilerServices
16 /// A factory type used by compilers to create instances of the type <see cref="FormattableString"/>.
18 public static class FormattableStringFactory
21 /// Create a <see cref="FormattableString"/> from a composite format string and object
22 /// array containing zero or more objects to format.
24 public static FormattableString Create(string format, params object[] arguments)
28 throw new ArgumentNullException("format");
31 if (arguments == null)
33 throw new ArgumentNullException("arguments");
36 return new ConcreteFormattableString(format, arguments);
39 private sealed class ConcreteFormattableString : FormattableString
41 private readonly string _format;
42 private readonly object[] _arguments;
44 internal ConcreteFormattableString(string format, object[] arguments)
47 _arguments = arguments;
50 public override string Format { get { return _format; } }
51 public override object[] GetArguments() { return _arguments; }
52 public override int ArgumentCount { get { return _arguments.Length; } }
53 public override object GetArgument(int index) { return _arguments[index]; }
54 public override string ToString(IFormatProvider formatProvider) { return string.Format(formatProvider, _format, _arguments); }