Skip to content

Instantly share code, notes, and snippets.

@ufcpp
Last active December 7, 2022 13:28
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 ufcpp/2262fe3f607974b68b849b5b47a4dc32 to your computer and use it in GitHub Desktop.
Save ufcpp/2262fe3f607974b68b849b5b47a4dc32 to your computer and use it in GitHub Desktop.
Convert T4 to StringBuilder.Append($$""" """);
using System.Text.RegularExpressions;
using System.Windows;
class Program
{
[STAThread]
static void Main()
{
var x = Clipboard.GetText();
x = Reg.A().Replace(x, m => "{{" + m.Groups[1].Value + "}}");
x = Reg.C().Replace(x, """"
s.Append($$$$"""
"""");
x = Reg.B().Replace(x, """"
""");
"""");
Clipboard.SetText(""""
public string TransformText()
{
var s = new StringBuilder();
s.Append($$"""
""""
+ x +
""""
""");
return s.ToString();
}
"""");
}
}
static partial class Reg
{
[GeneratedRegex("""
\<\#\=(.*?)\#\>
""", RegexOptions.Multiline)]
public static partial Regex A();
[GeneratedRegex("""
^\<\#
""", RegexOptions.Multiline)]
public static partial Regex B();
[GeneratedRegex("""
^\#\>
""", RegexOptions.Multiline)]
public static partial Regex C();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment