Skip to content

Instantly share code, notes, and snippets.

@svick
Created March 9, 2015 20:20
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save svick/e5b30f73146a501cc64f to your computer and use it in GitHub Desktop.
Save svick/e5b30f73146a501cc64f to your computer and use it in GitHub Desktop.
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