Created
December 20, 2022 18:30
-
-
Save mrange/575faabc88738aced5f56d7a141d2a76 to your computer and use it in GitHub Desktop.
Invariant String Interpolation
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
namespace SomeLib | |
{ | |
using System.Globalization; | |
using System.Runtime.CompilerServices; | |
static partial class StringInterpolation | |
{ | |
// This is to allow to use fast string interpolation | |
public static string FastInvariantInterpolation(ref DefaultInterpolatedStringHandler handler) | |
{ | |
return string.Create(CultureInfo.InvariantCulture, ref handler); | |
} | |
// This is how FormattableString.Invariant works | |
public static string SlowInvariantInterpolation(FormattableString fs) | |
{ | |
return fs.Format(CultureInfo.InvariantCulture, GetArguments()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment