Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
C# 6.0 FormattableString on .Net 4.0
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