Created
March 9, 2015 20:20
-
-
Save svick/e5b30f73146a501cc64f to your computer and use it in GitHub Desktop.
C# 6.0 FormattableString on .Net 4.0
This file contains hidden or 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
using System; | |
using System.Globalization; | |
static class Program | |
{ | |
private static void Main() | |
{ | |
double d = 3.14; | |
IFormattable s = $"{d}"; | |
Console.WriteLine(s.ToString(null, CultureInfo.GetCultureInfo("cs-cz"))); | |
Console.WriteLine(s.ToString(null, CultureInfo.InvariantCulture)); | |
} | |
} | |
namespace System.Runtime.CompilerServices | |
{ | |
static class FormattableStringFactory | |
{ | |
public static FormattableString Create(string s, params object[] args) | |
{ | |
return new FormattableString(s, args); | |
} | |
} | |
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(string ignored, IFormatProvider formatProvider) | |
{ | |
return string.Format(formatProvider, s, args); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment