An extendable source generator that builds on Roslyn's support for incremental generators.
Source generation can be triggered by specifying configuration information using:
- Type Attributes
- Yaml Files
- Json Files
- XML Files
The following template languages can be used to specify generated source code:
- Scriban
- Liquid (via Scriban's Liquid support)
Adding the following trigger file would generate an EF Core DbContext
for all classes in the project that include an attribute named DbEntity
.
srcLocatorType: MFFAttributeTypeLocator
srcLocatorInfo: Example.Data.DbEntityAttribute
genOutputInfos:
- fileNameBuilderInfo: 'ExampleDbContext.g.cs'
sourceBuilderType: MFFScribanBuilder
sourceBuilderInfo: |-
#nullable enable
using Microsoft.EntityFrameworkCore;
namespace Example.Data
public partial class ExampleContext : DbContext
{
public ExampleContext(DbContextOptions<ExampleContext> options) : base(options)
{
}
{{- for srcType in srcTypes }}
public DbSet<{{ srcType.Name }}> {{ srcType.Name }}s { get; set; }
{{- end }}
}
#nullable enable
using Microsoft.EntityFrameworkCore;
namespace Example.Data
public partial class ExampleContext : DbContext
{
public ExampleContext(DbContextOptions<ExampleContext> options) : base(options)
{
}
public DbSet<Example> Examples { get; set; }
public DbSet<AdditionalExample> AdditionalExamples { get; set; }
}