using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"modelBuilder\.Entity<(?'type'\w+)>\(builder =>\n\s*\{(?'builder'[\w\W]+?)\}\);";
string substitution = @"public class $1Mapping : IEntityTypeConfiguration<$1>\n{\n public void Configure(EntityTypeBuilder<$1> builder)\n {\n$2\n}}";
string input = @"modelBuilder.Entity<Foobar>(builder =>
{
builder.HasKey(e => e.Id).HasName(""PRIMARY"");
builder
.ToTable(""foobar"")
.UseCollation(""utf8mb4_0900_ai_ci"");
builder.HasIndex(e => e.A, ""A"").IsUnique();
builder.Property(e => e.D).HasColumnType(""datetime"");
builder.Property(e => e.E)
.HasMaxLength(255)
.UseCollation(""utf8mb4_unicode_ci"");
builder.Property(e => e.N)
.HasMaxLength(255)
.UseCollation(""utf8mb4_unicode_ci"");
builder.HasOne(d => d.ANav).WithOne(p => p.BNav)
.HasForeignKey<Foobar>(d => d.Leerling)
.HasConstraintName(""Foobar_fk"");
});";
RegexOptions options = RegexOptions.Multiline;
Regex regex = new Regex(pattern, options);
string result = regex.Replace(input, substitution);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx