-
-
Save jessehouwing/9dedb22f8cd4b79a782c to your computer and use it in GitHub Desktop.
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
// This is a .NET 3.5 console app, compiled with the C# 6 compiler from Visual Studio 2015 RTM | |
using System; | |
namespace System.Runtime.CompilerServices | |
{ | |
internal class FormattableStringFactory | |
{ | |
public static FormattableString Create(string messageFormat, params object[] args) | |
{ | |
return new FormattableString(messageFormat, args); | |
} | |
} | |
} | |
namespace System | |
{ | |
internal class FormattableString : IFormattable | |
{ | |
private readonly string messageFormat; | |
private readonly object[] args; | |
public FormattableString(string messageFormat, object[] args) | |
{ | |
this.messageFormat = messageFormat; | |
this.args = args; | |
} | |
public override string ToString() | |
{ | |
return string.Format(messageFormat, args); | |
} | |
public string ToString(string format, IFormatProvider formatProvider) | |
{ | |
return string.Format(formatProvider, format ?? messageFormat, args); | |
} | |
public string ToString(IFormatProvider formatProvider) | |
{ | |
return string.Format(formatProvider, messageFormat, args); | |
} | |
} | |
} | |
namespace ConsoleApp35 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int x = 10; | |
FormattableString fs = $"{nameof(x)}={x}"; | |
Console.WriteLine(fs); | |
fs = $"{DateTime.Now}: {nameof(x)}={x}"; | |
Console.WriteLine(fs); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment