Created
May 8, 2017 06:49
-
-
Save skyline75489/27d5c28cd8c075f805d2de187efef3d2 to your computer and use it in GitHub Desktop.
FormattableString on .NET 4.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System | |
{ | |
using System.Globalization; | |
public class FormattableString : IFormattable | |
{ | |
private readonly string s; | |
private readonly object[] args; | |
public FormattableString(string s, object[] args) | |
{ | |
this.s = s; | |
this.args = args; | |
} | |
public string ToString(IFormatProvider formatProvider) | |
{ | |
return string.Format(formatProvider, s, args); | |
} | |
string IFormattable.ToString(string ignored, IFormatProvider formatProvider) => this.ToString(formatProvider); | |
public override string ToString() => this.ToString(CultureInfo.CurrentCulture); | |
public static string Invariant(FormattableString formattable) | |
{ | |
if (formattable == null) | |
{ | |
throw new ArgumentNullException(nameof(formattable)); | |
} | |
return formattable.ToString(CultureInfo.InvariantCulture); | |
} | |
} | |
} | |
namespace System.Runtime.CompilerServices | |
{ | |
internal static class FormattableStringFactory | |
{ | |
public static FormattableString Create(string s, params object[] args) | |
{ | |
return new FormattableString(s, args); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment