Skip to content

Instantly share code, notes, and snippets.

@mrange
Created December 20, 2022 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrange/575faabc88738aced5f56d7a141d2a76 to your computer and use it in GitHub Desktop.
Save mrange/575faabc88738aced5f56d7a141d2a76 to your computer and use it in GitHub Desktop.
Invariant String Interpolation
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