Skip to content

Instantly share code, notes, and snippets.

@jessehouwing
Forked from jskeet/gist:9d297d0dc013d7a557ee
Last active August 29, 2015 14:27
Show Gist options
  • Save jessehouwing/9dedb22f8cd4b79a782c to your computer and use it in GitHub Desktop.
Save jessehouwing/9dedb22f8cd4b79a782c to your computer and use it in GitHub Desktop.

Revisions

  1. jessehouwing revised this gist Aug 18, 2015. 1 changed file with 14 additions and 11 deletions.
    25 changes: 14 additions & 11 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,28 +1,20 @@
    // This is a .NET 3.5 console app, compiled with the C# 6 compiler from CTP6
    // 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
    {
    public class FormattableStringFactory
    internal class FormattableStringFactory
    {
    public static FormattableString Create(string messageFormat, params object[] args)
    {
    return new FormattableString(messageFormat, args);
    }

    public static FormattableString Create(string messageFormat, DateTime bad, params object[] args)
    {
    var realArgs = new object[args.Length + 1];
    realArgs[0] = "Please don't use DateTime";
    Array.Copy(args, 0, realArgs, 1, args.Length);
    return new FormattableString(messageFormat, realArgs);
    }
    }
    }

    namespace System
    {
    public class FormattableString
    internal class FormattableString : IFormattable
    {
    private readonly string messageFormat;
    private readonly object[] args;
    @@ -32,10 +24,21 @@ namespace System
    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);
    }
    }
    }

  2. @jskeet jskeet created this gist Feb 23, 2015.
    56 changes: 56 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    // This is a .NET 3.5 console app, compiled with the C# 6 compiler from CTP6
    using System;

    namespace System.Runtime.CompilerServices
    {
    public class FormattableStringFactory
    {
    public static FormattableString Create(string messageFormat, params object[] args)
    {
    return new FormattableString(messageFormat, args);
    }

    public static FormattableString Create(string messageFormat, DateTime bad, params object[] args)
    {
    var realArgs = new object[args.Length + 1];
    realArgs[0] = "Please don't use DateTime";
    Array.Copy(args, 0, realArgs, 1, args.Length);
    return new FormattableString(messageFormat, realArgs);
    }
    }
    }

    namespace System
    {
    public class FormattableString
    {
    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);
    }
    }
    }

    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);
    }
    }
    }